annotate libinterp/dldfcn/__ode15__.cc @ 25438:cb1606f78f6b

prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible Using <iostream> brings with it a static initializer for the std::cin, std::cout, and std::cerr streams. In most cases they are not needed and should be avoided if possible. Files affected: build-aux/mk-opts.pl libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp libinterp/corefcn/__dsearchn__.cc libinterp/corefcn/c-file-ptr-stream.cc libinterp/corefcn/c-file-ptr-stream.h libinterp/corefcn/daspk.cc libinterp/corefcn/dasrt.cc libinterp/corefcn/dassl.cc libinterp/corefcn/defaults.cc libinterp/corefcn/defun.cc libinterp/corefcn/file-io.cc libinterp/corefcn/ft-text-renderer.cc libinterp/corefcn/gl-render.cc libinterp/corefcn/help.cc libinterp/corefcn/ls-ascii-helper.cc libinterp/corefcn/ls-hdf5.cc libinterp/corefcn/ls-hdf5.h libinterp/corefcn/ls-mat-ascii.cc libinterp/corefcn/ls-mat4.cc libinterp/corefcn/ls-mat5.cc libinterp/corefcn/ls-oct-binary.cc libinterp/corefcn/ls-oct-text.cc libinterp/corefcn/lsode.cc libinterp/corefcn/oct-iostrm.cc libinterp/corefcn/oct-procbuf.cc libinterp/corefcn/oct-stdstrm.h libinterp/corefcn/procstream.cc libinterp/corefcn/procstream.h libinterp/corefcn/quad.cc libinterp/corefcn/symscope.h libinterp/corefcn/symtab.h libinterp/corefcn/toplev.cc libinterp/corefcn/urlwrite.cc libinterp/corefcn/utils.cc libinterp/corefcn/zfstream.cc libinterp/dldfcn/__ode15__.cc libinterp/dldfcn/convhulln.cc libinterp/octave-value/ov-base-diag.cc libinterp/octave-value/ov-base-int.cc libinterp/octave-value/ov-base-mat.cc libinterp/octave-value/ov-base-scalar.cc libinterp/octave-value/ov-base-sparse.cc libinterp/octave-value/ov-base.cc libinterp/octave-value/ov-bool-mat.cc libinterp/octave-value/ov-bool-sparse.cc libinterp/octave-value/ov-bool.cc libinterp/octave-value/ov-cell.cc libinterp/octave-value/ov-ch-mat.cc libinterp/octave-value/ov-class.cc libinterp/octave-value/ov-colon.cc libinterp/octave-value/ov-complex.cc libinterp/octave-value/ov-cs-list.cc libinterp/octave-value/ov-cx-mat.cc libinterp/octave-value/ov-cx-sparse.cc libinterp/octave-value/ov-fcn-handle.cc libinterp/octave-value/ov-fcn-inline.cc libinterp/octave-value/ov-float.cc libinterp/octave-value/ov-flt-complex.cc libinterp/octave-value/ov-flt-cx-mat.cc libinterp/octave-value/ov-flt-re-mat.cc libinterp/octave-value/ov-int16.cc libinterp/octave-value/ov-int32.cc libinterp/octave-value/ov-int64.cc libinterp/octave-value/ov-int8.cc libinterp/octave-value/ov-java.cc libinterp/octave-value/ov-range.cc libinterp/octave-value/ov-re-mat.cc libinterp/octave-value/ov-re-sparse.cc libinterp/octave-value/ov-scalar.cc libinterp/octave-value/ov-str-mat.cc libinterp/octave-value/ov-struct.cc libinterp/octave-value/ov-typeinfo.cc libinterp/octave-value/ov-uint16.cc libinterp/octave-value/ov-uint32.cc libinterp/octave-value/ov-uint64.cc libinterp/octave-value/ov-uint8.cc libinterp/octave.cc libinterp/parse-tree/bp-table.cc libinterp/parse-tree/lex.h libinterp/parse-tree/profiler.cc libinterp/parse-tree/pt-arg-list.cc libinterp/parse-tree/pt-array-list.cc libinterp/parse-tree/pt-assign.cc libinterp/parse-tree/pt-cell.cc libinterp/parse-tree/pt-const.cc libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-exp.cc libinterp/parse-tree/pt-fcn-handle.cc libinterp/parse-tree/pt-jit.cc libinterp/parse-tree/pt-pr-code.cc libinterp/parse-tree/pt-tm-const.cc libinterp/parse-tree/pt.cc liboctave/array/Array.cc liboctave/array/CColVector.cc liboctave/array/CDiagMatrix.cc liboctave/array/CMatrix.cc liboctave/array/CNDArray.cc liboctave/array/CRowVector.cc liboctave/array/CSparse.cc liboctave/array/DiagArray2.cc liboctave/array/MArray.cc liboctave/array/Range.cc liboctave/array/Sparse.cc liboctave/array/boolMatrix.cc liboctave/array/boolSparse.cc liboctave/array/chMatrix.cc liboctave/array/dColVector.cc liboctave/array/dDiagMatrix.cc liboctave/array/dMatrix.cc liboctave/array/dNDArray.cc liboctave/array/dRowVector.cc liboctave/array/dSparse.cc liboctave/array/fCColVector.cc liboctave/array/fCDiagMatrix.cc liboctave/array/fCMatrix.cc liboctave/array/fCNDArray.cc liboctave/array/fCRowVector.cc liboctave/array/fColVector.cc liboctave/array/fDiagMatrix.cc liboctave/array/fMatrix.cc liboctave/array/fNDArray.cc liboctave/array/fRowVector.cc liboctave/array/idx-vector.cc liboctave/numeric/CollocWt.cc liboctave/numeric/eigs-base.cc liboctave/system/file-ops.cc liboctave/system/oct-time.cc liboctave/util/cmd-hist.cc liboctave/util/data-conv.cc liboctave/util/data-conv.h liboctave/util/file-info.cc liboctave/util/lo-utils.cc liboctave/util/lo-utils.h liboctave/util/quit.cc liboctave/util/str-vec.cc liboctave/util/url-transfer.cc liboctave/util/url-transfer.h
author John W. Eaton <jwe@octave.org>
date Thu, 07 Jun 2018 10:11:54 -0400
parents 078b795c5219
children 97e63ba8a34c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1 /*
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
2
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3 Copyright (C) 2016-2018 Francesco Faccio <francesco.faccio@mail.polimi.it>
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
4
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
5 This file is part of Octave.
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24444
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24444
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
24007
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23795
diff changeset
10 (at your option) any later version.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
11
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
24007
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23795
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23795
diff changeset
15 GNU General Public License for more details.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
16
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24444
diff changeset
19 <https://www.gnu.org/licenses/>.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
20
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
21 */
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
22
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
23 #if defined (HAVE_CONFIG_H)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
24 # include "config.h"
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
25 #endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
26
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
27 #include <iostream>
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
28
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
29 #include "dColVector.h"
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
30 #include "dMatrix.h"
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
31 #include "dSparse.h"
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
32
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 23022
diff changeset
33 #include "Cell.h"
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
34 #include "defun-dld.h"
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
35 #include "error.h"
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 23022
diff changeset
36 #include "errwarn.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 23022
diff changeset
37 #include "oct-map.h"
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
38 #include "ov.h"
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 23022
diff changeset
39 #include "ovl.h"
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
40 #include "parse.h"
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
41
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
42 #if defined (HAVE_SUNDIALS)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
43
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
44 # if defined (HAVE_IDA_IDA_H)
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
45 # include <ida/ida.h>
25098
5dce8aa80652 configure: disable SUNDIALS if the IDADENSE API is not found (bug #52475)
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
46 # endif
5dce8aa80652 configure: disable SUNDIALS if the IDADENSE API is not found (bug #52475)
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
47
5dce8aa80652 configure: disable SUNDIALS if the IDADENSE API is not found (bug #52475)
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
48 # if defined (HAVE_IDA_IDA_DENSE_H)
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
49 # include <ida/ida_dense.h>
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
50 # endif
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
51
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
52 # if defined (HAVE_IDA_IDA_KLU_H)
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
53 # include <ida/ida_klu.h>
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
54 # include <sundials/sundials_sparse.h>
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
55 # endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
56
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
57 # if defined (HAVE_NVECTOR_NVECTOR_SERIAL_H)
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
58 # include <nvector/nvector_serial.h>
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
59 # endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
60
22915
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
61 static inline realtype *
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
62 nv_data_s (N_Vector& v)
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
63 {
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
64 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
24444
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24007
diff changeset
65 // Disable warning from GCC about old-style casts in Sundials
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24007
diff changeset
66 // macro expansions. Do this in a function so that this
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24007
diff changeset
67 // diagnostic may still be enabled for the rest of the file.
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24007
diff changeset
68 # pragma GCC diagnostic push
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24007
diff changeset
69 # pragma GCC diagnostic ignored "-Wold-style-cast"
22915
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
70 #endif
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
71
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
72 return NV_DATA_S (v);
23085
dffa2b8c9482 maint: strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23075
diff changeset
73
22915
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
74 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
24444
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24007
diff changeset
75 // Restore prevailing warning state for remainder of the file.
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24007
diff changeset
76 # pragma GCC diagnostic pop
22915
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
77 #endif
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
78 }
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
79
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
80 namespace octave
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
81 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
82 class IDA
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
83 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
84 public:
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
85
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
86 typedef
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
87 ColumnVector (*DAERHSFuncIDA) (const ColumnVector& x,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
88 const ColumnVector& xdot,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
89 realtype t, octave_function *idaf);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
90
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
91 typedef
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
92 Matrix (*DAEJacFuncDense) (const ColumnVector& x,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
93 const ColumnVector& xdot, realtype t,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
94 realtype cj, octave_function *idaj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
95
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
96 typedef
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
97 SparseMatrix (*DAEJacFuncSparse) (const ColumnVector& x,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
98 const ColumnVector& xdot,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
99 realtype t, realtype cj,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
100 octave_function *idaj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
101
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
102 typedef
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
103 Matrix (*DAEJacCellDense) (Matrix *dfdy, Matrix *dfdyp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
104 realtype cj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
105
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
106 typedef
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
107 SparseMatrix (*DAEJacCellSparse) (SparseMatrix *dfdy,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
108 SparseMatrix *dfdyp, realtype cj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
109
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
110 //Default
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
111 IDA (void)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
112 : t0 (0.0), y0 (), yp0 (), havejac (false), havejacfun (false),
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
113 havejacsparse (false), mem (nullptr), num (), ida_fun (nullptr),
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
114 ida_jac (nullptr), dfdy (nullptr), dfdyp (nullptr), spdfdy (nullptr),
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
115 spdfdyp (nullptr), fun (nullptr), jacfun (nullptr), jacspfun (nullptr),
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
116 jacdcell (nullptr), jacspcell (nullptr)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
117 { }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
118
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
119
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
120 IDA (realtype t, ColumnVector y, ColumnVector yp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
121 octave_function *ida_fcn, DAERHSFuncIDA daefun)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
122 : t0 (t), y0 (y), yp0 (yp), havejac (false), havejacfun (false),
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
123 havejacsparse (false), mem (nullptr), num (), ida_fun (ida_fcn),
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
124 ida_jac (nullptr), dfdy (nullptr), dfdyp (nullptr), spdfdy (nullptr),
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
125 spdfdyp (nullptr), fun (daefun), jacfun (nullptr), jacspfun (nullptr),
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
126 jacdcell (nullptr), jacspcell (nullptr)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
127 { }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
128
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
129
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
130 ~IDA (void) { IDAFree (&mem); }
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
131
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
132 IDA&
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
133 set_jacobian (octave_function *jac, DAEJacFuncDense j)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
134 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
135 jacfun = j;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
136 ida_jac = jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
137 havejac = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
138 havejacfun = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
139 havejacsparse = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
140 return *this;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
141 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
142
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
143 IDA&
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
144 set_jacobian (octave_function *jac, DAEJacFuncSparse j)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
145 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
146 jacspfun = j;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
147 ida_jac = jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
148 havejac = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
149 havejacfun = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
150 havejacsparse = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
151 return *this;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
152 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
153
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
154 IDA&
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
155 set_jacobian (Matrix *dy, Matrix *dyp, DAEJacCellDense j)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
156 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
157 jacdcell = j;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
158 dfdy = dy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
159 dfdyp = dyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
160 havejac = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
161 havejacfun = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
162 havejacsparse = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
163 return *this;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
164 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
165
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
166 IDA&
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
167 set_jacobian (SparseMatrix *dy, SparseMatrix *dyp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
168 DAEJacCellSparse j)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
169 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
170 jacspcell = j;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
171 spdfdy = dy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
172 spdfdyp = dyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
173 havejac = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
174 havejacfun = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
175 havejacsparse = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
176 return *this;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
177 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
178
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
179 void set_userdata (void);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
180
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
181 void initialize (void);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
182
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
183 static ColumnVector NVecToCol (N_Vector& v, long int n);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
184
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
185 static N_Vector ColToNVec (const ColumnVector& data, long int n);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
186
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
187 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
188 set_up (void);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
189
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
190 void
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
191 set_tolerance (ColumnVector& abstol, realtype reltol);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
192
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
193 void
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
194 set_tolerance (realtype abstol, realtype reltol);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
195
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
196 static int
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
197 resfun (realtype t, N_Vector yy, N_Vector yyp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
198 N_Vector rr, void *user_data);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
199
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
200 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
201 resfun_impl (realtype t, N_Vector& yy,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
202 N_Vector& yyp, N_Vector& rr);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
203
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
204 static int
22914
b7ffd93b8d06 * __ode15__.cc: Avoid unused parameter warnings.
John W. Eaton <jwe@octave.org>
parents: 22913
diff changeset
205 jacdense (long int Neq, realtype t, realtype cj, N_Vector yy,
b7ffd93b8d06 * __ode15__.cc: Avoid unused parameter warnings.
John W. Eaton <jwe@octave.org>
parents: 22913
diff changeset
206 N_Vector yyp, N_Vector, DlsMat JJ, void *user_data,
b7ffd93b8d06 * __ode15__.cc: Avoid unused parameter warnings.
John W. Eaton <jwe@octave.org>
parents: 22913
diff changeset
207 N_Vector, N_Vector, N_Vector)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
208 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
209 IDA *self = static_cast <IDA *> (user_data);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
210 self->jacdense_impl (Neq, t, cj, yy, yyp, JJ);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
211 return 0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
212 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
213
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
214 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
215 jacdense_impl (long int Neq, realtype t, realtype cj,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
216 N_Vector& yy, N_Vector& yyp, DlsMat& JJ);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
217
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
218 # if defined (HAVE_SUNDIALS_IDAKLU)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
219 static int
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
220 jacsparse (realtype t, realtype cj, N_Vector yy, N_Vector yyp,
22914
b7ffd93b8d06 * __ode15__.cc: Avoid unused parameter warnings.
John W. Eaton <jwe@octave.org>
parents: 22913
diff changeset
221 N_Vector, SlsMat Jac, void *user_data, N_Vector,
b7ffd93b8d06 * __ode15__.cc: Avoid unused parameter warnings.
John W. Eaton <jwe@octave.org>
parents: 22913
diff changeset
222 N_Vector, N_Vector)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
223 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
224 IDA *self = static_cast <IDA *> (user_data);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
225 self->jacsparse_impl (t, cj, yy, yyp, Jac);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
226 return 0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
227 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
228
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
229 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
230 jacsparse_impl (realtype t, realtype cj, N_Vector& yy,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
231 N_Vector& yyp, SlsMat& Jac);
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
232 #endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
233
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
234 void set_maxstep (realtype maxstep);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
235
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
236 void set_initialstep (realtype initialstep);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
237
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
238 bool
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
239 interpolate (int& cont, Matrix& output, ColumnVector& tout,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
240 int refine, realtype tend, bool haveoutputfcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
241 bool haveoutputsel, octave_function *output_fcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
242 ColumnVector& outputsel, bool haveeventfunction,
23432
e35a5c1233d0 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23221
diff changeset
243 octave_function *event_fcn, ColumnVector& te,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
244 Matrix& ye, ColumnVector& ie, ColumnVector& oldval,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
245 ColumnVector& oldisterminal, ColumnVector& olddir,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
246 int& temp, ColumnVector& yold);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
247
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
248 bool
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
249 outputfun (octave_function *output_fcn, bool haveoutputsel,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
250 const ColumnVector& output, realtype tout, realtype tend,
22918
0b5d9978d7b1 * __ode15__.cc: Pass std::string arg by const reference.
John W. Eaton <jwe@octave.org>
parents: 22917
diff changeset
251 ColumnVector& outputsel, const std::string& flag);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
252
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
253
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
254 bool
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
255 event (octave_function *event_fcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
256 ColumnVector& te, Matrix& ye, ColumnVector& ie,
22918
0b5d9978d7b1 * __ode15__.cc: Pass std::string arg by const reference.
John W. Eaton <jwe@octave.org>
parents: 22917
diff changeset
257 realtype tsol, const ColumnVector& y, const std::string& flag,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
258 const ColumnVector& yp, ColumnVector& oldval,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
259 ColumnVector& oldisterminal, ColumnVector& olddir,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
260 int cont, int& temp, realtype told, ColumnVector& yold);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
261
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
262 void set_maxorder (int maxorder);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
263
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
264 octave_value_list
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
265 integrate (const int numt, const ColumnVector& tt,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
266 const ColumnVector& y0, const ColumnVector& yp0,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
267 const int refine, bool haverefine, bool haveoutputfcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
268 octave_function *output_fcn, bool haveoutputsel,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
269 ColumnVector& outputsel, bool haveeventfunction,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
270 octave_function *event_fcn);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
271
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
272 void print_stat (void);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
273
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
274 private:
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
275
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
276 realtype t0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
277 ColumnVector y0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
278 ColumnVector yp0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
279 bool havejac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
280 bool havejacfun;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
281 bool havejacsparse;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
282 void *mem;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
283 int num;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
284 octave_function *ida_fun;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
285 octave_function *ida_jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
286 Matrix *dfdy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
287 Matrix *dfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
288 SparseMatrix *spdfdy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
289 SparseMatrix *spdfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
290 DAERHSFuncIDA fun;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
291 DAEJacFuncDense jacfun;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
292 DAEJacFuncSparse jacspfun;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
293 DAEJacCellDense jacdcell;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
294 DAEJacCellSparse jacspcell;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
295 };
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
296
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
297 int
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
298 IDA::resfun (realtype t, N_Vector yy, N_Vector yyp, N_Vector rr,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
299 void *user_data)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
300 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
301 IDA *self = static_cast <IDA *> (user_data);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
302 self->resfun_impl (t, yy, yyp, rr);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
303 return 0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
304 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
305
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
306 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
307 IDA::resfun_impl (realtype t, N_Vector& yy,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
308 N_Vector& yyp, N_Vector& rr)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
309 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
310 BEGIN_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
311
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
312 ColumnVector y = IDA::NVecToCol (yy, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
313
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
314 ColumnVector yp = IDA::NVecToCol (yyp, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
315
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
316 ColumnVector res = (*fun) (y, yp, t, ida_fun);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
317
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
318 realtype *puntrr = nv_data_s (rr);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
319
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
320 for (octave_idx_type i = 0; i < num; i++)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
321 puntrr[i] = res(i);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
322
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
323 END_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
324 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
325
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
326 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
327 IDA::set_up (void)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
328 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
329 if (havejacsparse)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
330 {
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
331 # if defined (HAVE_SUNDIALS_IDAKLU)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
332 if (IDAKLU (mem, num, num*num, CSC_MAT) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
333 error ("IDAKLU solver not initialized");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
334
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
335 IDASlsSetSparseJacFn (mem, IDA::jacsparse);
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
336 # else
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
337 error ("IDAKLU is not available in this version of Octave");
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
338 # endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
339 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
340 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
341 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
342 if (IDADense (mem, num) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
343 error ("IDADense solver not initialized");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
344
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
345 if (havejac && IDADlsSetDenseJacFn (mem, IDA::jacdense) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
346 error ("Dense Jacobian not set");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
347 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
348 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
349
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
350 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
351 IDA::jacdense_impl (long int Neq, realtype t, realtype cj,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
352 N_Vector& yy, N_Vector& yyp, DlsMat& JJ)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
353
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
354 {
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
355 BEGIN_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
356
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
357 ColumnVector y = NVecToCol (yy, Neq);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
358
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
359 ColumnVector yp = NVecToCol (yyp, Neq);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
360
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
361 Matrix jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
362
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
363 if (havejacfun)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
364 jac = (*jacfun) (y, yp, t, cj, ida_jac);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
365 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
366 jac = (*jacdcell) (dfdy, dfdyp, cj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
367
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
368 std::copy (jac.fortran_vec (),
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
369 jac.fortran_vec () + jac.numel (),
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
370 JJ->data);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
371
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
372 END_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
373 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
374
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
375 # if defined (HAVE_SUNDIALS_IDAKLU)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
376 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
377 IDA::jacsparse_impl (realtype t, realtype cj, N_Vector& yy, N_Vector& yyp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
378 SlsMat& Jac)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
379
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
380 {
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
381 BEGIN_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
382
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
383 ColumnVector y = NVecToCol (yy, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
384
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
385 ColumnVector yp = NVecToCol (yyp, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
386
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
387 SparseMatrix jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
388
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
389 if (havejacfun)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
390 jac = (*jacspfun) (y, yp, t, cj, ida_jac);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
391 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
392 jac = (*jacspcell) (spdfdy, spdfdyp, cj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
393
22902
284bbb0328f2 Update odei5{i,s} code for Octave 4.3.0+ and Sundials 2.7.0.
Carlo de Falco <carlo.defalco@polimi.it>
parents: 22901
diff changeset
394 SparseSetMatToZero (Jac);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
395 int *colptrs = *(Jac->colptrs);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
396 int *rowvals = *(Jac->rowvals);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
397
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
398 for (int i = 0; i < num + 1; i++)
22903
51c9eded34ee Fix access method to sundials 2.7.0 sparse matrix structure.
Carlo de Falco <carlo.defalco@polimi.it>
parents: 22902
diff changeset
399 colptrs[i] = jac.cidx(i);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
400
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
401 for (int i = 0; i < jac.nnz (); i++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
402 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
403 rowvals[i] = jac.ridx(i);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
404 Jac->data[i] = jac.data(i);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
405 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
406
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
407 END_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
408 }
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
409 #endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
410
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
411 ColumnVector
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
412 IDA::NVecToCol (N_Vector& v, long int n)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
413 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
414 ColumnVector data (n);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
415 realtype *punt = nv_data_s (v);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
416
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
417 for (octave_idx_type i = 0; i < n; i++)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
418 data(i) = punt[i];
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
419
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
420 return data;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
421 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
422
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
423 N_Vector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23432
diff changeset
424 IDA::ColToNVec (const ColumnVector& data, long int n)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
425 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
426 N_Vector v = N_VNew_Serial (n);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
427
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
428 realtype *punt = nv_data_s (v);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
429
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
430 for (octave_idx_type i = 0; i < n; i++)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
431 punt[i] = data(i);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
432
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
433 return v;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
434 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
435
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
436 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
437 IDA::set_userdata (void)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
438 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
439 void *userdata = this;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
440
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
441 if (IDASetUserData (mem, userdata) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
442 error ("User data not set");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
443 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
444
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
445 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
446 IDA::initialize (void)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
447 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
448 num = y0.numel ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
449 mem = IDACreate ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
450
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
451 N_Vector yy = ColToNVec (y0, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
452
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
453 N_Vector yyp = ColToNVec (yp0, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
454
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
455 IDA::set_userdata ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
456
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
457 if (IDAInit (mem, IDA::resfun, t0, yy, yyp) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
458 error ("IDA not initialized");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
459 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
460
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
461 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
462 IDA::set_tolerance (ColumnVector& abstol, realtype reltol)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
463 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
464 N_Vector abs_tol = ColToNVec (abstol, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
465
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
466 if (IDASVtolerances (mem, reltol, abs_tol) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
467 error ("IDA: Tolerance not set");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
468
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
469 N_VDestroy_Serial (abs_tol);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
470 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
471
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
472 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
473 IDA::set_tolerance (realtype abstol, realtype reltol)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
474 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
475 if (IDASStolerances (mem, reltol, abstol) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
476 error ("IDA: Tolerance not set");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
477 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
478
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
479 octave_value_list
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
480 IDA::integrate (const int numt, const ColumnVector& tspan,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
481 const ColumnVector& y, const ColumnVector& yp,
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
482 const int refine, bool haverefine, bool haveoutputfcn,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
483 octave_function *output_fcn, bool haveoutputsel,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
484 ColumnVector& outputsel, bool haveeventfunction,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
485 octave_function *event_fcn)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
486 {
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
487 // Set up output
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
488 ColumnVector tout, yout (num), ypout (num), ysel (outputsel.numel ());
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
489 ColumnVector ie, te, oldval, oldisterminal, olddir;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
490 Matrix output, ye;
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
491 int cont = 0, temp = 0;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
492 bool status = 0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
493 std::string string = "";
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
494 ColumnVector yold = y;
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
495
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
496 realtype tsol = tspan(0);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
497 realtype tend = tspan(numt-1);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
498
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
499 N_Vector yyp = ColToNVec (yp, num);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
500
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
501 N_Vector yy = ColToNVec (y, num);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
502
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
503 // Initialize OutputFcn
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
504 if (haveoutputfcn)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
505 status = IDA::outputfun (output_fcn, haveoutputsel, y,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
506 tsol, tend, outputsel, "init");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
507
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
508 // Initialize Events
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
509 if (haveeventfunction)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
510 status = IDA::event (event_fcn, te, ye, ie, tsol, y,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
511 "init", yp, oldval, oldisterminal,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
512 olddir, cont, temp, tsol, yold);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
513
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
514 if (numt > 2)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
515 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
516 // First output value
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
517 tout.resize (numt);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
518 tout(0) = tsol;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
519 output.resize (numt, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
520
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
521 for (octave_idx_type i = 0; i < num; i++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
522 output.elem (0, i) = y.elem (i);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
523
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
524 //Main loop
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
525 for (octave_idx_type j = 1; j < numt && status == 0; j++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
526 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
527 // IDANORMAL already interpolates tspan(j)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
528
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
529 if (IDASolve (mem, tspan (j), &tsol, yy, yyp, IDA_NORMAL) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
530 error ("IDASolve failed");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
531
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
532 yout = NVecToCol (yy, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
533 ypout = NVecToCol (yyp, num);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
534 tout(j) = tsol;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
535
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
536 for (octave_idx_type i = 0; i < num; i++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
537 output.elem (j, i) = yout.elem (i);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
538
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
539 if (haveoutputfcn)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
540 status = IDA::outputfun (output_fcn, haveoutputsel, yout, tsol,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
541 tend, outputsel, string);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
542
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
543 if (haveeventfunction)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
544 status = IDA::event (event_fcn, te, ye, ie, tout(j), yout,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
545 string, ypout, oldval, oldisterminal,
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
546 olddir, j, temp, tout(j-1), yold);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
547
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
548 // If integration is stopped, return only the reached steps
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
549 if (status == 1)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
550 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
551 output.resize (j + 1, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
552 tout.resize (j + 1);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
553 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
554
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
555 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
556 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
557 else // numel (tspan) == 2
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
558 {
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
559 // First output value
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
560 tout.resize (1);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
561 tout(0) = tsol;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
562 output.resize (1, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
563
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
564 for (octave_idx_type i = 0; i < num; i++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
565 output.elem (0, i) = y.elem (i);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
566
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
567 bool posdirection = (tend > tsol);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
568
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
569 //main loop
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
570 while (((posdirection == 1 && tsol < tend)
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25098
diff changeset
571 || (posdirection == 0 && tsol > tend))
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
572 && status == 0)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
573 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
574 if (IDASolve (mem, tend, &tsol, yy, yyp, IDA_ONE_STEP) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
575 error ("IDASolve failed");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
576
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
577 if (haverefine)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
578 status = IDA::interpolate (cont, output, tout, refine, tend,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
579 haveoutputfcn, haveoutputsel,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
580 output_fcn, outputsel,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
581 haveeventfunction, event_fcn, te,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
582 ye, ie, oldval, oldisterminal,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
583 olddir, temp, yold);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
584
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
585 ypout = NVecToCol (yyp, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
586 cont += 1;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
587 output.resize (cont + 1, num); // This may be not efficient
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
588 tout.resize (cont + 1);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
589 tout(cont) = tsol;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
590 yout = NVecToCol (yy, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
591
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
592 for (octave_idx_type i = 0; i < num; i++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
593 output.elem (cont, i) = yout.elem (i);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
594
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
595 if (haveoutputfcn && ! haverefine && tout(cont) < tend)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
596 status = IDA::outputfun (output_fcn, haveoutputsel, yout, tsol,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
597 tend, outputsel, string);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
598
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
599 if (haveeventfunction && ! haverefine && tout(cont) < tend)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
600 status = IDA::event (event_fcn, te, ye, ie, tout(cont), yout,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
601 string, ypout, oldval, oldisterminal,
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
602 olddir, cont, temp, tout(cont-1), yold);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
603 }
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
604
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
605 if (status == 0)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
606 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
607 // Interpolate in tend
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
608 N_Vector dky = N_VNew_Serial (num);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
609
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
610 if (IDAGetDky (mem, tend, 0, dky) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
611 error ("IDA failed to interpolate y");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
612
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
613 tout(cont) = tend;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
614 yout = NVecToCol (dky, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
615
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
616 for (octave_idx_type i = 0; i < num; i++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
617 output.elem (cont, i) = yout.elem (i);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
618
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
619 // Plot final value
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
620 if (haveoutputfcn)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
621 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
622 status = IDA::outputfun (output_fcn, haveoutputsel, yout,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
623 tend, tend, outputsel, string);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
624
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
625 // Events during last step
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
626 if (haveeventfunction)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
627 status = IDA::event (event_fcn, te, ye, ie, tend, yout,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
628 string, ypout, oldval, oldisterminal,
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
629 olddir, cont, temp, tout(cont-1),
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
630 yold);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
631 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
632
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
633 N_VDestroy_Serial (dky);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
634 }
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
635
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
636 // Cleanup plotter
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
637 status = IDA::outputfun (output_fcn, haveoutputsel, yout, tend, tend,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
638 outputsel, "done");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
639
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
640 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
641
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
642 return ovl (tout, output, te, ye, ie);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
643 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
644
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
645 bool
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
646 IDA::event (octave_function *event_fcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
647 ColumnVector& te, Matrix& ye, ColumnVector& ie,
22918
0b5d9978d7b1 * __ode15__.cc: Pass std::string arg by const reference.
John W. Eaton <jwe@octave.org>
parents: 22917
diff changeset
648 realtype tsol, const ColumnVector& y, const std::string& flag,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
649 const ColumnVector& yp, ColumnVector& oldval,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
650 ColumnVector& oldisterminal, ColumnVector& olddir, int cont,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
651 int& temp, realtype told, ColumnVector& yold)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
652 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
653 bool status = 0;
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
654
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
655 octave_value_list args = ovl (tsol, y, yp);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
656
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
657 // cont is the number of steps reached by the solver
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
658 // temp is the number of events registered
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
659
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
660 if (flag == "init")
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
661 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
662 octave_value_list output = feval (event_fcn, args, 3);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
663 oldval = output(0).vector_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
664 oldisterminal = output(1).vector_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
665 olddir = output(2).vector_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
666 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
667 else if (flag == "")
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
668 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
669 ColumnVector index (0);
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
670 octave_value_list output = feval (event_fcn, args, 3);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
671 ColumnVector val = output(0).vector_value ();
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
672 ColumnVector isterminal = output(1).vector_value ();
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
673 ColumnVector dir = output(2).vector_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
674
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
675 // Get the index of the changed values
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
676 for (octave_idx_type i = 0; i < val.numel (); i++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
677 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
678 if ((val(i) > 0 && oldval(i) < 0 && dir(i) != -1) // increasing
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
679 || (val(i) < 0 && oldval(i) > 0 && dir(i) != 1)) // decreasing
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
680 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
681 index.resize (index.numel () + 1);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
682 index (index.numel () - 1) = i;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
683 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
684 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
685
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
686 if (cont == 1 && index.numel () > 0) // Events in first step
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
687 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
688 temp = 1; // register only the first event
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
689 te.resize (1);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
690 ye.resize (1, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
691 ie.resize (1);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
692
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
693 // Linear interpolation
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
694 ie(0) = index(0);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
695 te(0) = tsol - val (index(0)) * (tsol - told)
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25098
diff changeset
696 / (val (index(0)) - oldval (index(0)));
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
697
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
698 ColumnVector ytemp
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
699 = y - ((tsol - te(0)) * (y - yold) / (tsol - told));
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
700
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
701 for (octave_idx_type i = 0; i < num; i++)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
702 ye.elem (0, i) = ytemp.elem (i);
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
703
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
704 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
705 else if (index.numel () > 0)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
706 // Not first step: register all events and test if stop integration or not
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
707 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
708 te.resize (temp + index.numel ());
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
709 ye.resize (temp + index.numel (), num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
710 ie.resize (temp + index.numel ());
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
711
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
712 for (octave_idx_type i = 0; i < index.numel (); i++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
713 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
714
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
715 if (isterminal (index(i)) == 1)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
716 status = 1; // Stop integration
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
717
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
718 // Linear interpolation
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
719 ie(temp+i) = index(i);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
720 te(temp+i) = tsol - val(index(i)) * (tsol - told)
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25098
diff changeset
721 / (val(index(i)) - oldval(index(i)));
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
722
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
723 ColumnVector ytemp
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
724 = y - (tsol - te (temp + i)) * (y - yold) / (tsol - told);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
725
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
726 for (octave_idx_type j = 0; j < num; j++)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
727 ye.elem (temp + i, j) = ytemp.elem (j);
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
728
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
729 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
730
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
731 temp += index.numel ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
732 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
733
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
734 // Update variables
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
735 yold = y;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
736 told = tsol;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
737 olddir = dir;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
738 oldval = val;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
739 oldisterminal = isterminal;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
740 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
741
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
742 return status;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
743 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
744
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
745 bool
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
746 IDA::interpolate (int& cont, Matrix& output, ColumnVector& tout,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
747 int refine, realtype tend, bool haveoutputfcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
748 bool haveoutputsel, octave_function *output_fcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
749 ColumnVector& outputsel, bool haveeventfunction,
23432
e35a5c1233d0 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23221
diff changeset
750 octave_function *event_fcn, ColumnVector& te,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
751 Matrix& ye, ColumnVector& ie, ColumnVector& oldval,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
752 ColumnVector& oldisterminal, ColumnVector& olddir,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
753 int& temp, ColumnVector& yold)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
754 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
755 realtype h = 0, tcur = 0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
756 bool status = 0;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
757
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
758 N_Vector dky = N_VNew_Serial (num);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
759
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
760 N_Vector dkyp = N_VNew_Serial (num);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
761
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
762 ColumnVector yout (num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
763 ColumnVector ypout (num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
764 std::string string = "";
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
765
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
766 if (IDAGetLastStep (mem, &h) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
767 error ("IDA failed to return last step");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
768
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
769 if (IDAGetCurrentTime (mem, &tcur) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
770 error ("IDA failed to return the current time");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
771
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
772 realtype tin = tcur - h;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
773
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
774 realtype step = h / refine;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
775
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
776 for (octave_idx_type i = 1;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
777 i < refine && tin + step * i < tend && status == 0;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
778 i++)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
779 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
780 if (IDAGetDky (mem, tin + step*i, 0, dky) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
781 error ("IDA failed to interpolate y");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
782
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
783 if (IDAGetDky (mem, tin + step*i, 1, dkyp) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
784 error ("IDA failed to interpolate yp");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
785
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
786 cont += 1;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
787 output.resize (cont + 1, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
788 tout.resize (cont + 1);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
789
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
790 tout(cont) = tin + step * i;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
791 yout = NVecToCol (dky, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
792 ypout = NVecToCol (dkyp, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
793
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
794 for (octave_idx_type j = 0; j < num; j++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
795 output.elem (cont, j) = yout.elem (j);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
796
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
797 if (haveoutputfcn)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
798 status = IDA::outputfun (output_fcn, haveoutputsel, yout,
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
799 tout(cont), tend, outputsel, "");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
800
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
801 if (haveeventfunction)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
802 status = IDA::event (event_fcn, te, ye, ie, tout(cont),
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
803 yout, string, ypout, oldval,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
804 oldisterminal, olddir, cont, temp,
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
805 tout(cont-1), yold);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
806 }
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
807
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
808 N_VDestroy_Serial (dky);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
809
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
810 return status;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
811 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
812
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
813 bool
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
814 IDA::outputfun (octave_function *output_fcn, bool haveoutputsel,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
815 const ColumnVector& yout, realtype tsol,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
816 realtype tend, ColumnVector& outputsel,
22918
0b5d9978d7b1 * __ode15__.cc: Pass std::string arg by const reference.
John W. Eaton <jwe@octave.org>
parents: 22917
diff changeset
817 const std::string& flag)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
818 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
819 bool status = 0;
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
820
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
821 octave_value_list output;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
822 output(2) = flag;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
823
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
824 ColumnVector ysel (outputsel.numel ());
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
825 if (haveoutputsel)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
826 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
827 for (octave_idx_type i = 0; i < outputsel.numel (); i++)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
828 ysel(i) = yout(outputsel(i));
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
829
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
830 output(1) = ysel;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
831 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
832 else
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
833 output(1) = yout;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
834
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
835 if (flag == "init")
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
836 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
837 ColumnVector toutput(2);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
838 toutput(0) = tsol;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
839 toutput(1) = tend;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
840 output(0) = toutput;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
841
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
842 feval (output_fcn, output, 0);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
843 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
844 else if (flag == "")
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
845 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
846 output(0) = tsol;
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
847 octave_value_list val = feval (output_fcn, output, 1);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
848 status = val(0).bool_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
849 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
850 else
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25098
diff changeset
851 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25098
diff changeset
852 // Cleanup plotter
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
853 output(0) = tend;
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
854 feval (output_fcn, output, 0);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
855 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
856
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
857 return status;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
858 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
859
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
860 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
861 IDA::set_maxstep (realtype maxstep)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
862 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
863 if (IDASetMaxStep (mem, maxstep) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
864 error ("IDA: Max Step not set");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
865 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
866
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
867 void
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
868 IDA::set_initialstep (realtype initialstep)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
869 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
870 if (IDASetInitStep (mem, initialstep) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
871 error ("IDA: Initial Step not set");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
872 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
873
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
874 void
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
875 IDA::set_maxorder (int maxorder)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
876 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
877 if (IDASetMaxOrd (mem, maxorder) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
878 error ("IDA: Max Order not set");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
879 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
880
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
881 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
882 IDA::print_stat (void)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
883 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
884 long int nsteps = 0, netfails = 0, nrevals = 0;
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
885
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
886 if (IDAGetNumSteps (mem, &nsteps) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
887 error ("IDA failed to return the number of internal steps");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
888
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
889 if (IDAGetNumErrTestFails (mem, &netfails) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
890 error ("IDA failed to return the number of internal errors");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
891
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
892 if (IDAGetNumResEvals (mem, &nrevals) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
893 error ("IDA failed to return the number of residual evaluations");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
894
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
895 std::cout << nsteps << " successful steps\n";
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
896 std::cout << netfails << " failed attempts\n";
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
897 std::cout << nrevals << " function evaluations\n";
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
898 // std::cout << " partial derivatives\n";
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
899 // std::cout << " LU decompositions\n";
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
900 // std::cout << " solutions of linear systems\n";
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
901 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
902
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
903 ColumnVector
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
904 ida_user_function (const ColumnVector& x, const ColumnVector& xdot,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
905 double t, octave_function *ida_fc)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
906 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
907 octave_value_list tmp;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
908
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
909 try
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
910 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
911 tmp = feval (ida_fc, ovl (t, x, xdot), 1);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
912 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
913 catch (execution_exception& e)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
914 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
915 err_user_supplied_eval (e, "__ode15__");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
916 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
917
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
918 return tmp(0).vector_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
919 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
920
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
921 Matrix
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
922 ida_dense_jac (const ColumnVector& x, const ColumnVector& xdot,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
923 double t, double cj, octave_function *ida_jc)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
924 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
925 octave_value_list tmp;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
926
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
927 try
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
928 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
929 tmp = feval (ida_jc, ovl (t, x, xdot), 2);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
930 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
931 catch (execution_exception& e)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
932 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
933 err_user_supplied_eval (e, "__ode15__");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
934 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
935
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
936 return tmp(0).matrix_value () + cj * tmp(1).matrix_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
937 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
938
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
939 SparseMatrix
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
940 ida_sparse_jac (const ColumnVector& x, const ColumnVector& xdot,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
941 double t, double cj, octave_function *ida_jc)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
942 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
943 octave_value_list tmp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
944
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
945 try
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
946 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
947 tmp = feval (ida_jc, ovl (t, x, xdot), 2);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
948 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
949 catch (execution_exception& e)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
950 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
951 err_user_supplied_eval (e, "__ode15__");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
952 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
953
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
954 return tmp(0).sparse_matrix_value () + cj * tmp(1).sparse_matrix_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
955 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
956
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
957 Matrix
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
958 ida_dense_cell_jac (Matrix *dfdy, Matrix *dfdyp, double cj)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
959 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
960 return (*dfdy) + cj * (*dfdyp);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
961 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
962
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
963 SparseMatrix
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
964 ida_sparse_cell_jac (SparseMatrix *spdfdy, SparseMatrix *spdfdyp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
965 double cj)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
966 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
967 return (*spdfdy) + cj * (*spdfdyp);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
968 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
969
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
970 octave_value_list
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
971 do_ode15 (octave_function *ida_fcn,
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23432
diff changeset
972 const ColumnVector& tspan,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
973 const int numt,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
974 const realtype t0,
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23432
diff changeset
975 const ColumnVector& y0,
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23432
diff changeset
976 const ColumnVector& yp0,
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23432
diff changeset
977 const octave_scalar_map& options)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
978 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
979 octave_value_list retval;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
980
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
981 // Create object
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
982 IDA dae (t0, y0, yp0, ida_fcn, ida_user_function);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
983
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
984 // Set Jacobian
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
985 bool havejac = options.getfield ("havejac").bool_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
986
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
987 bool havejacsparse = options.getfield ("havejacsparse").bool_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
988
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
989 bool havejacfun = options.getfield ("havejacfun").bool_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
990
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
991 Matrix ida_dfdy, ida_dfdyp, *dfdy, *dfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
992 SparseMatrix ida_spdfdy, ida_spdfdyp, *spdfdy, *spdfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
993 octave_function *ida_jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
994 Cell jaccell;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
995
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
996 if (havejac)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
997 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
998 if (havejacfun)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
999 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1000 ida_jac = options.getfield ("Jacobian").function_value ();
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1001
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1002 if (havejacsparse)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1003 dae.set_jacobian (ida_jac, ida_sparse_jac);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1004 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1005 dae.set_jacobian (ida_jac, ida_dense_jac);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1006 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1007 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1008 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1009 jaccell = options.getfield ("Jacobian").cell_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1010
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1011 if (havejacsparse)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1012 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1013 ida_spdfdy = jaccell(0).sparse_matrix_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1014 ida_spdfdyp = jaccell(1).sparse_matrix_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1015 spdfdy = &ida_spdfdy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1016 spdfdyp = &ida_spdfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1017 dae.set_jacobian (spdfdy, spdfdyp, ida_sparse_cell_jac);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1018 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1019 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1020 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1021 ida_dfdy = jaccell(0).matrix_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1022 ida_dfdyp = jaccell(1).matrix_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1023 dfdy = &ida_dfdy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1024 dfdyp = &ida_dfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1025 dae.set_jacobian (dfdy, dfdyp, ida_dense_cell_jac);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1026 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1027 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1028 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1029
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1030 // Initialize IDA
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1031 dae.initialize ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1032
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1033 // Set tolerances
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1034 realtype rel_tol = options.getfield("RelTol").double_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1035
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1036 bool haveabstolvec = options.getfield ("haveabstolvec").bool_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1037
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1038 if (haveabstolvec)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1039 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1040 ColumnVector abs_tol = options.getfield("AbsTol").vector_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1041
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1042 dae.set_tolerance (abs_tol, rel_tol);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1043 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1044 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1045 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1046 realtype abs_tol = options.getfield("AbsTol").double_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1047
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1048 dae.set_tolerance (abs_tol, rel_tol);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1049 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1050
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1051 //Set max step
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1052 realtype maxstep = options.getfield("MaxStep").double_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1053
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1054 dae.set_maxstep (maxstep);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1055
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1056 //Set initial step
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23565
diff changeset
1057 if (! options.getfield("InitialStep").isempty ())
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1058 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1059 realtype initialstep = options.getfield("InitialStep").double_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1060
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1061 dae.set_initialstep (initialstep);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1062 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1063
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1064 //Set max order FIXME: it doesn't work
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1065 int maxorder = options.getfield("MaxOrder").int_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1066
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1067 dae.set_maxorder (maxorder);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1068
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1069 //Set Refine
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1070 const int refine = options.getfield("Refine").int_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1071
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1072 bool haverefine = (refine > 1);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1073
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23433
diff changeset
1074 octave_function *output_fcn = nullptr;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1075 ColumnVector outputsel;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1076
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1077 // OutputFcn
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1078 bool haveoutputfunction
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1079 = options.getfield("haveoutputfunction").bool_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1080
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1081 if (haveoutputfunction)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1082 output_fcn = options.getfield("OutputFcn").function_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1083
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1084 // OutputSel
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1085 bool haveoutputsel = options.getfield("haveoutputselection").bool_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1086
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1087 if (haveoutputsel)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1088 outputsel = options.getfield("OutputSel").vector_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1089
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23433
diff changeset
1090 octave_function *event_fcn = nullptr;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1091
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1092 // Events
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1093 bool haveeventfunction
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1094 = options.getfield("haveeventfunction").bool_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1095
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1096 if (haveeventfunction)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1097 event_fcn = options.getfield("Events").function_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1098
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1099 // Set up linear solver
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1100 dae.set_up ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1101
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1102 // Integrate
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1103 retval = dae.integrate (numt, tspan, y0, yp0, refine,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1104 haverefine, haveoutputfunction,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1105 output_fcn, haveoutputsel, outputsel,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1106 haveeventfunction, event_fcn);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1107
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1108 // Statistics
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1109 bool havestats = options.getfield("havestats").bool_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1110
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1111 if (havestats)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1112 dae.print_stat ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1113
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1114 return retval;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1115 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1116 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1117 #endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1118
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1119
22913
69342e4f0dcf * __ode15__.cc: Don't check nargout.
John W. Eaton <jwe@octave.org>
parents: 22912
diff changeset
1120 DEFUN_DLD (__ode15__, args, ,
69342e4f0dcf * __ode15__.cc: Don't check nargout.
John W. Eaton <jwe@octave.org>
parents: 22912
diff changeset
1121 doc: /* -*- texinfo -*-
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23480
diff changeset
1122 @deftypefn {} {@var{t}, @var{y} =} __ode15__ (@var{fun}, @var{tspan}, @var{y0}, @var{yp0}, @var{options})
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1123 Undocumented internal function.
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1124 @end deftypefn */)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1125 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1126
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1127 #if defined (HAVE_SUNDIALS)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1128
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1129 // Check number of parameters
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1130 int nargin = args.length ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1131
22913
69342e4f0dcf * __ode15__.cc: Don't check nargout.
John W. Eaton <jwe@octave.org>
parents: 22912
diff changeset
1132 if (nargin != 5)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1133 print_usage ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1134
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1135 // Check odefun
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23433
diff changeset
1136 octave_function *ida_fcn = nullptr;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1137
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1138 octave_value f_arg = args(0);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1139
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1140 if (! f_arg.is_function_handle ())
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1141 error ("__ode15__: odefun must be a function handle");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1142
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1143 ida_fcn = f_arg.function_value ();
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1144
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1145 // Check input tspan
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1146 ColumnVector tspan
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1147 = args(1).xvector_value ("__ode15__: TRANGE must be a vector of numbers");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1148
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1149 int numt = tspan.numel ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1150
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1151 realtype t0 = tspan (0);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1152
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1153 if (numt < 2)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1154 error ("__ode15__: TRANGE must contain at least 2 elements");
23588
0549061d35b9 maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents: 23584
diff changeset
1155 else if (! tspan.issorted () || tspan(0) == tspan(numt - 1))
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1156 error ("__ode15__: TRANGE must be strictly monotonic");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1157
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1158 // input y0 and yp0
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1159 ColumnVector y0
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1160 = args(2).xvector_value ("__ode15__: initial state y0 must be a vector");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1161
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1162 ColumnVector yp0
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1163 = args(3).xvector_value ("__ode15__: initial state yp0 must be a vector");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1164
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1165
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1166 if (y0.numel () != yp0.numel ())
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1167 error ("__ode15__: initial state y0 and yp0 must have the same length");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1168 else if (y0.numel () < 1)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1169 error ("__ode15__: initial state yp0 must be a vector or a scalar");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1170
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1171
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23577
diff changeset
1172 if (! args(4).isstruct ())
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1173 error ("__ode15__: OPTS argument must be a structure");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1174
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1175 octave_scalar_map options
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1176 = args(4).xscalar_map_value ("__ode15__: OPTS argument must be a scalar structure");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1177
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1178
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1179 return octave::do_ode15 (ida_fcn, tspan, numt, t0, y0, yp0, options);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1180
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1181
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1182 #else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1183
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1184 octave_unused_parameter (args);
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
1185
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1186 err_disabled_feature ("__ode15__", "sundials_ida, sundials_nvecserial");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1187
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1188 #endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1189 }