annotate libinterp/dldfcn/__ode15__.cc @ 26376:00f796120a6d stable

maint: Update copyright dates in all source files.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Jan 2019 16:32:43 -0500
parents 97e63ba8a34c
children 9ec0a1e5d4d3
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
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26000
diff changeset
3 Copyright (C) 2016-2019 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
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
27 #include "dColVector.h"
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
28 #include "dMatrix.h"
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
29 #include "dSparse.h"
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
30
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 23022
diff changeset
31 #include "Cell.h"
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
32 #include "defun-dld.h"
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
33 #include "error.h"
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 23022
diff changeset
34 #include "errwarn.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 23022
diff changeset
35 #include "oct-map.h"
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
36 #include "ov.h"
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 23022
diff changeset
37 #include "ovl.h"
26000
97e63ba8a34c * __ode15__.cc (IDA::print_stat): Use octave_stdout instead of std::cout.
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
38 #include "pager.h"
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
39 #include "parse.h"
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
40
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
41 #if defined (HAVE_SUNDIALS)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
42
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
43 # 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
44 # 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
45 # endif
5dce8aa80652 configure: disable SUNDIALS if the IDADENSE API is not found (bug #52475)
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
46
5dce8aa80652 configure: disable SUNDIALS if the IDADENSE API is not found (bug #52475)
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
47 # 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
48 # 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
49 # endif
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
50
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
51 # 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
52 # include <ida/ida_klu.h>
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
53 # include <sundials/sundials_sparse.h>
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
54 # endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
55
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
56 # 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
57 # include <nvector/nvector_serial.h>
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
58 # endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
59
22915
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
60 static inline realtype *
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
61 nv_data_s (N_Vector& v)
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
62 {
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
63 #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
64 // 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
65 // 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
66 // 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
67 # pragma GCC diagnostic push
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24007
diff changeset
68 # 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
69 #endif
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
70
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
71 return NV_DATA_S (v);
23085
dffa2b8c9482 maint: strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23075
diff changeset
72
22915
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
73 #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
74 // 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
75 # pragma GCC diagnostic pop
22915
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
76 #endif
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
77 }
7766e3ef6c69 * __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 22914
diff changeset
78
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
79 namespace octave
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
80 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
81 class IDA
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
82 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
83 public:
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
84
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
85 typedef
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
86 ColumnVector (*DAERHSFuncIDA) (const ColumnVector& x,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
87 const ColumnVector& xdot,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
88 realtype t, octave_function *idaf);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
89
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
90 typedef
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
91 Matrix (*DAEJacFuncDense) (const ColumnVector& x,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
92 const ColumnVector& xdot, realtype t,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
93 realtype cj, octave_function *idaj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
94
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
95 typedef
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
96 SparseMatrix (*DAEJacFuncSparse) (const ColumnVector& x,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
97 const ColumnVector& xdot,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
98 realtype t, realtype cj,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
99 octave_function *idaj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
100
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
101 typedef
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
102 Matrix (*DAEJacCellDense) (Matrix *dfdy, Matrix *dfdyp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
103 realtype cj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
104
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
105 typedef
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
106 SparseMatrix (*DAEJacCellSparse) (SparseMatrix *dfdy,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
107 SparseMatrix *dfdyp, realtype cj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
108
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
109 //Default
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
110 IDA (void)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
111 : 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
112 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
113 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
114 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
115 jacdcell (nullptr), jacspcell (nullptr)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
116 { }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
117
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 IDA (realtype t, ColumnVector y, ColumnVector yp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
120 octave_function *ida_fcn, DAERHSFuncIDA daefun)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
121 : 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
122 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
123 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
124 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
125 jacdcell (nullptr), jacspcell (nullptr)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
126 { }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
127
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
128
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
129 ~IDA (void) { IDAFree (&mem); }
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
130
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
131 IDA&
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
132 set_jacobian (octave_function *jac, DAEJacFuncDense j)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
133 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
134 jacfun = j;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
135 ida_jac = jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
136 havejac = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
137 havejacfun = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
138 havejacsparse = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
139 return *this;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
140 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
141
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
142 IDA&
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
143 set_jacobian (octave_function *jac, DAEJacFuncSparse j)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
144 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
145 jacspfun = j;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
146 ida_jac = jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
147 havejac = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
148 havejacfun = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
149 havejacsparse = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
150 return *this;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
151 }
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 IDA&
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
154 set_jacobian (Matrix *dy, Matrix *dyp, DAEJacCellDense j)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
155 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
156 jacdcell = j;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
157 dfdy = dy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
158 dfdyp = dyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
159 havejac = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
160 havejacfun = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
161 havejacsparse = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
162 return *this;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
163 }
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 IDA&
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
166 set_jacobian (SparseMatrix *dy, SparseMatrix *dyp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
167 DAEJacCellSparse j)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
168 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
169 jacspcell = j;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
170 spdfdy = dy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
171 spdfdyp = dyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
172 havejac = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
173 havejacfun = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
174 havejacsparse = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
175 return *this;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
176 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
177
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
178 void set_userdata (void);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
179
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
180 void initialize (void);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
181
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
182 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
183
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
184 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
185
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
186 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
187 set_up (void);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
188
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
189 void
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
190 set_tolerance (ColumnVector& abstol, realtype reltol);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
191
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
192 void
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
193 set_tolerance (realtype abstol, realtype reltol);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
194
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
195 static int
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
196 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
197 N_Vector rr, void *user_data);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
198
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
199 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
200 resfun_impl (realtype t, N_Vector& yy,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
201 N_Vector& yyp, N_Vector& rr);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
202
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
203 static int
22914
b7ffd93b8d06 * __ode15__.cc: Avoid unused parameter warnings.
John W. Eaton <jwe@octave.org>
parents: 22913
diff changeset
204 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
205 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
206 N_Vector, N_Vector, N_Vector)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
207 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
208 IDA *self = static_cast <IDA *> (user_data);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
209 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
210 return 0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
211 }
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 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
214 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
215 N_Vector& yy, N_Vector& yyp, DlsMat& JJ);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
216
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
217 # if defined (HAVE_SUNDIALS_IDAKLU)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
218 static int
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
219 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
220 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
221 N_Vector, N_Vector)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
222 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
223 IDA *self = static_cast <IDA *> (user_data);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
224 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
225 return 0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
226 }
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 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
229 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
230 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
231 #endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
232
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
233 void set_maxstep (realtype maxstep);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
234
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
235 void set_initialstep (realtype initialstep);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
236
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
237 bool
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
238 interpolate (int& cont, Matrix& output, ColumnVector& tout,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
239 int refine, realtype tend, bool haveoutputfcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
240 bool haveoutputsel, octave_function *output_fcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
241 ColumnVector& outputsel, bool haveeventfunction,
23432
e35a5c1233d0 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23221
diff changeset
242 octave_function *event_fcn, ColumnVector& te,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
243 Matrix& ye, ColumnVector& ie, ColumnVector& oldval,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
244 ColumnVector& oldisterminal, ColumnVector& olddir,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
245 int& temp, ColumnVector& yold);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
246
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
247 bool
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
248 outputfun (octave_function *output_fcn, bool haveoutputsel,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
249 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
250 ColumnVector& outputsel, const std::string& flag);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
251
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 bool
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
254 event (octave_function *event_fcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
255 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
256 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
257 const ColumnVector& yp, ColumnVector& oldval,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
258 ColumnVector& oldisterminal, ColumnVector& olddir,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
259 int cont, int& temp, realtype told, ColumnVector& yold);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
260
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
261 void set_maxorder (int maxorder);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
262
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
263 octave_value_list
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
264 integrate (const int numt, const ColumnVector& tt,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
265 const ColumnVector& y0, const ColumnVector& yp0,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
266 const int refine, bool haverefine, bool haveoutputfcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
267 octave_function *output_fcn, bool haveoutputsel,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
268 ColumnVector& outputsel, bool haveeventfunction,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
269 octave_function *event_fcn);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
270
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
271 void print_stat (void);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
272
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
273 private:
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
274
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
275 realtype t0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
276 ColumnVector y0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
277 ColumnVector yp0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
278 bool havejac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
279 bool havejacfun;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
280 bool havejacsparse;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
281 void *mem;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
282 int num;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
283 octave_function *ida_fun;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
284 octave_function *ida_jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
285 Matrix *dfdy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
286 Matrix *dfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
287 SparseMatrix *spdfdy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
288 SparseMatrix *spdfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
289 DAERHSFuncIDA fun;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
290 DAEJacFuncDense jacfun;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
291 DAEJacFuncSparse jacspfun;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
292 DAEJacCellDense jacdcell;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
293 DAEJacCellSparse jacspcell;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
294 };
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 int
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
297 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
298 void *user_data)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
299 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
300 IDA *self = static_cast <IDA *> (user_data);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
301 self->resfun_impl (t, yy, yyp, rr);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
302 return 0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
303 }
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 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
306 IDA::resfun_impl (realtype t, N_Vector& yy,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
307 N_Vector& yyp, N_Vector& rr)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
308 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
309 BEGIN_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
310
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
311 ColumnVector y = IDA::NVecToCol (yy, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
312
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
313 ColumnVector yp = IDA::NVecToCol (yyp, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
314
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
315 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
316
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
317 realtype *puntrr = nv_data_s (rr);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
318
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
319 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
320 puntrr[i] = res(i);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
321
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
322 END_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
323 }
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 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
326 IDA::set_up (void)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
327 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
328 if (havejacsparse)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
329 {
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
330 # if defined (HAVE_SUNDIALS_IDAKLU)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
331 if (IDAKLU (mem, num, num*num, CSC_MAT) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
332 error ("IDAKLU solver not initialized");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
333
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
334 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
335 # else
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
336 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
337 # endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
338 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
339 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
340 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
341 if (IDADense (mem, num) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
342 error ("IDADense solver not initialized");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
343
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
344 if (havejac && IDADlsSetDenseJacFn (mem, IDA::jacdense) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
345 error ("Dense Jacobian not set");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
346 }
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 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
350 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
351 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
352
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
353 {
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
354 BEGIN_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
355
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
356 ColumnVector y = NVecToCol (yy, Neq);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
357
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
358 ColumnVector yp = NVecToCol (yyp, Neq);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
359
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
360 Matrix jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
361
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
362 if (havejacfun)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
363 jac = (*jacfun) (y, yp, t, cj, ida_jac);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
364 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
365 jac = (*jacdcell) (dfdy, dfdyp, cj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
366
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
367 std::copy (jac.fortran_vec (),
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
368 jac.fortran_vec () + jac.numel (),
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
369 JJ->data);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
370
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
371 END_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
372 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
373
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
374 # if defined (HAVE_SUNDIALS_IDAKLU)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
375 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
376 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
377 SlsMat& Jac)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
378
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
379 {
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
380 BEGIN_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
381
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
382 ColumnVector y = NVecToCol (yy, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
383
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
384 ColumnVector yp = NVecToCol (yyp, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
385
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
386 SparseMatrix jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
387
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
388 if (havejacfun)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
389 jac = (*jacspfun) (y, yp, t, cj, ida_jac);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
390 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
391 jac = (*jacspcell) (spdfdy, spdfdyp, cj);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
392
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
393 SparseSetMatToZero (Jac);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
394 int *colptrs = *(Jac->colptrs);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
395 int *rowvals = *(Jac->rowvals);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
396
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
397 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
398 colptrs[i] = jac.cidx(i);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
399
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
400 for (int i = 0; i < jac.nnz (); i++)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
401 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
402 rowvals[i] = jac.ridx(i);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
403 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
404 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
405
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
406 END_INTERRUPT_WITH_EXCEPTIONS;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
407 }
23022
305cdc1d444b * __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents: 22919
diff changeset
408 #endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
409
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
410 ColumnVector
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
411 IDA::NVecToCol (N_Vector& v, long int n)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
412 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
413 ColumnVector data (n);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
414 realtype *punt = nv_data_s (v);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
415
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
416 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
417 data(i) = punt[i];
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
418
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
419 return data;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
420 }
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 N_Vector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23432
diff changeset
423 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
424 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
425 N_Vector v = N_VNew_Serial (n);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
426
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
427 realtype *punt = nv_data_s (v);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
428
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
429 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
430 punt[i] = data(i);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
431
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
432 return v;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
433 }
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 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
436 IDA::set_userdata (void)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
437 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
438 void *userdata = this;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
439
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
440 if (IDASetUserData (mem, userdata) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
441 error ("User data not set");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
442 }
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 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
445 IDA::initialize (void)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
446 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
447 num = y0.numel ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
448 mem = IDACreate ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
449
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
450 N_Vector yy = ColToNVec (y0, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
451
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
452 N_Vector yyp = ColToNVec (yp0, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
453
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
454 IDA::set_userdata ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
455
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
456 if (IDAInit (mem, IDA::resfun, t0, yy, yyp) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
457 error ("IDA not initialized");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
458 }
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 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
461 IDA::set_tolerance (ColumnVector& abstol, realtype reltol)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
462 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
463 N_Vector abs_tol = ColToNVec (abstol, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
464
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
465 if (IDASVtolerances (mem, reltol, abs_tol) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
466 error ("IDA: Tolerance not set");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
467
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
468 N_VDestroy_Serial (abs_tol);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
469 }
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 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
472 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
473 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
474 if (IDASStolerances (mem, reltol, abstol) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
475 error ("IDA: Tolerance not set");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
476 }
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 octave_value_list
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
479 IDA::integrate (const int numt, const ColumnVector& tspan,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
480 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
481 const int refine, bool haverefine, bool haveoutputfcn,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
482 octave_function *output_fcn, bool haveoutputsel,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
483 ColumnVector& outputsel, bool haveeventfunction,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
484 octave_function *event_fcn)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
485 {
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
486 // Set up output
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
487 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
488 ColumnVector ie, te, oldval, oldisterminal, olddir;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
489 Matrix output, ye;
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
490 int cont = 0, temp = 0;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
491 bool status = 0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
492 std::string string = "";
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
493 ColumnVector yold = y;
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
494
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
495 realtype tsol = tspan(0);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
496 realtype tend = tspan(numt-1);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
497
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
498 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
499
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
500 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
501
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
502 // Initialize OutputFcn
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
503 if (haveoutputfcn)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
504 status = IDA::outputfun (output_fcn, haveoutputsel, y,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
505 tsol, tend, outputsel, "init");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
506
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
507 // Initialize Events
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
508 if (haveeventfunction)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
509 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
510 "init", yp, oldval, oldisterminal,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
511 olddir, cont, temp, tsol, yold);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
512
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
513 if (numt > 2)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
514 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
515 // First output value
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
516 tout.resize (numt);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
517 tout(0) = tsol;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
518 output.resize (numt, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
519
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
520 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
521 output.elem (0, i) = y.elem (i);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
522
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
523 //Main loop
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
524 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
525 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
526 // IDANORMAL already interpolates tspan(j)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
527
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
528 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
529 error ("IDASolve failed");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
530
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
531 yout = NVecToCol (yy, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
532 ypout = NVecToCol (yyp, num);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
533 tout(j) = tsol;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
534
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
535 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
536 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
537
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
538 if (haveoutputfcn)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
539 status = IDA::outputfun (output_fcn, haveoutputsel, yout, tsol,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
540 tend, outputsel, string);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
541
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
542 if (haveeventfunction)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
543 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
544 string, ypout, oldval, oldisterminal,
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
545 olddir, j, temp, tout(j-1), yold);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
546
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
547 // 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
548 if (status == 1)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
549 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
550 output.resize (j + 1, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
551 tout.resize (j + 1);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
552 }
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 else // numel (tspan) == 2
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
557 {
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
558 // First output value
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
559 tout.resize (1);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
560 tout(0) = tsol;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
561 output.resize (1, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
562
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
563 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
564 output.elem (0, i) = y.elem (i);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
565
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
566 bool posdirection = (tend > tsol);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
567
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
568 //main loop
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
569 while (((posdirection == 1 && tsol < tend)
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25098
diff changeset
570 || (posdirection == 0 && tsol > tend))
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
571 && status == 0)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
572 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
573 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
574 error ("IDASolve failed");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
575
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
576 if (haverefine)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
577 status = IDA::interpolate (cont, output, tout, refine, tend,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
578 haveoutputfcn, haveoutputsel,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
579 output_fcn, outputsel,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
580 haveeventfunction, event_fcn, te,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
581 ye, ie, oldval, oldisterminal,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
582 olddir, temp, yold);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
583
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
584 ypout = NVecToCol (yyp, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
585 cont += 1;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
586 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
587 tout.resize (cont + 1);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
588 tout(cont) = tsol;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
589 yout = NVecToCol (yy, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
590
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
591 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
592 output.elem (cont, i) = yout.elem (i);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
593
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
594 if (haveoutputfcn && ! haverefine && tout(cont) < tend)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
595 status = IDA::outputfun (output_fcn, haveoutputsel, yout, tsol,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
596 tend, outputsel, string);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
597
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
598 if (haveeventfunction && ! haverefine && tout(cont) < tend)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
599 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
600 string, ypout, oldval, oldisterminal,
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
601 olddir, cont, temp, tout(cont-1), yold);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
602 }
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
603
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
604 if (status == 0)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
605 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
606 // Interpolate in tend
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
607 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
608
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
609 if (IDAGetDky (mem, tend, 0, dky) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
610 error ("IDA failed to interpolate y");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
611
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
612 tout(cont) = tend;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
613 yout = NVecToCol (dky, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
614
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
615 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
616 output.elem (cont, i) = yout.elem (i);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
617
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
618 // Plot final value
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
619 if (haveoutputfcn)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
620 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
621 status = IDA::outputfun (output_fcn, haveoutputsel, yout,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
622 tend, tend, outputsel, string);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
623
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
624 // Events during last step
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
625 if (haveeventfunction)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
626 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
627 string, ypout, oldval, oldisterminal,
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
628 olddir, cont, temp, tout(cont-1),
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
629 yold);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
630 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
631
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
632 N_VDestroy_Serial (dky);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
633 }
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
634
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
635 // Cleanup plotter
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
636 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
637 outputsel, "done");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
638
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
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
641 return ovl (tout, output, te, ye, ie);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
642 }
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 bool
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
645 IDA::event (octave_function *event_fcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
646 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
647 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
648 const ColumnVector& yp, ColumnVector& oldval,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
649 ColumnVector& oldisterminal, ColumnVector& olddir, int cont,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
650 int& temp, realtype told, ColumnVector& yold)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
651 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
652 bool status = 0;
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
653
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
654 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
655
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
656 // 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
657 // temp is the number of events registered
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
658
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
659 if (flag == "init")
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
660 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
661 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
662 oldval = output(0).vector_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
663 oldisterminal = output(1).vector_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
664 olddir = output(2).vector_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
665 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
666 else if (flag == "")
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
667 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
668 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
669 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
670 ColumnVector val = output(0).vector_value ();
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
671 ColumnVector isterminal = output(1).vector_value ();
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
672 ColumnVector dir = output(2).vector_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
673
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
674 // Get the index of the changed values
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
675 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
676 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
677 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
678 || (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
679 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
680 index.resize (index.numel () + 1);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
681 index (index.numel () - 1) = i;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
682 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
683 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
684
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
685 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
686 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
687 temp = 1; // register only the first event
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
688 te.resize (1);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
689 ye.resize (1, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
690 ie.resize (1);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
691
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
692 // Linear interpolation
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
693 ie(0) = index(0);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
694 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
695 / (val (index(0)) - oldval (index(0)));
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
696
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
697 ColumnVector ytemp
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
698 = 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
699
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
700 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
701 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
702
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
703 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
704 else if (index.numel () > 0)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
705 // 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
706 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
707 te.resize (temp + index.numel ());
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
708 ye.resize (temp + index.numel (), num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
709 ie.resize (temp + index.numel ());
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
710
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
711 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
712 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
713
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
714 if (isterminal (index(i)) == 1)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
715 status = 1; // Stop integration
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
716
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
717 // Linear interpolation
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
718 ie(temp+i) = index(i);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
719 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
720 / (val(index(i)) - oldval(index(i)));
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
721
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
722 ColumnVector ytemp
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
723 = 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
724
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
725 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
726 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
727
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
728 }
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 temp += index.numel ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
731 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
732
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
733 // Update variables
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
734 yold = y;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
735 told = tsol;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
736 olddir = dir;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
737 oldval = val;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
738 oldisterminal = isterminal;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
739 }
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 return status;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
742 }
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 bool
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
745 IDA::interpolate (int& cont, Matrix& output, ColumnVector& tout,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
746 int refine, realtype tend, bool haveoutputfcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
747 bool haveoutputsel, octave_function *output_fcn,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
748 ColumnVector& outputsel, bool haveeventfunction,
23432
e35a5c1233d0 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23221
diff changeset
749 octave_function *event_fcn, ColumnVector& te,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
750 Matrix& ye, ColumnVector& ie, ColumnVector& oldval,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
751 ColumnVector& oldisterminal, ColumnVector& olddir,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
752 int& temp, ColumnVector& yold)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
753 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
754 realtype h = 0, tcur = 0;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
755 bool status = 0;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
756
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
757 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
758
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
759 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
760
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
761 ColumnVector yout (num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
762 ColumnVector ypout (num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
763 std::string string = "";
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
764
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
765 if (IDAGetLastStep (mem, &h) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
766 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
767
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
768 if (IDAGetCurrentTime (mem, &tcur) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
769 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
770
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
771 realtype tin = tcur - h;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
772
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
773 realtype step = h / refine;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
774
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
775 for (octave_idx_type i = 1;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
776 i < refine && tin + step * i < tend && status == 0;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
777 i++)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
778 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
779 if (IDAGetDky (mem, tin + step*i, 0, dky) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
780 error ("IDA failed to interpolate y");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
781
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
782 if (IDAGetDky (mem, tin + step*i, 1, dkyp) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
783 error ("IDA failed to interpolate yp");
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
784
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
785 cont += 1;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
786 output.resize (cont + 1, num);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
787 tout.resize (cont + 1);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
788
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
789 tout(cont) = tin + step * i;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
790 yout = NVecToCol (dky, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
791 ypout = NVecToCol (dkyp, num);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
792
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
793 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
794 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
795
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
796 if (haveoutputfcn)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
797 status = IDA::outputfun (output_fcn, haveoutputsel, yout,
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
798 tout(cont), tend, outputsel, "");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
799
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
800 if (haveeventfunction)
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
801 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
802 yout, string, ypout, oldval,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
803 oldisterminal, olddir, cont, temp,
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
804 tout(cont-1), yold);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
805 }
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
806
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
807 N_VDestroy_Serial (dky);
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
808
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
809 return status;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
810 }
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 bool
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
813 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
814 const ColumnVector& yout, realtype tsol,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
815 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
816 const std::string& flag)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
817 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
818 bool status = 0;
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
819
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
820 octave_value_list output;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
821 output(2) = flag;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
822
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
823 ColumnVector ysel (outputsel.numel ());
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
824 if (haveoutputsel)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
825 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
826 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
827 ysel(i) = yout(outputsel(i));
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
828
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
829 output(1) = ysel;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
830 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
831 else
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
832 output(1) = yout;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
833
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
834 if (flag == "init")
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
835 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
836 ColumnVector toutput(2);
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
837 toutput(0) = tsol;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
838 toutput(1) = tend;
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
839 output(0) = toutput;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
840
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
841 feval (output_fcn, output, 0);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
842 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
843 else if (flag == "")
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
844 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
845 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
846 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
847 status = val(0).bool_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
848 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
849 else
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25098
diff changeset
850 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25098
diff changeset
851 // Cleanup plotter
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
852 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
853 feval (output_fcn, output, 0);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
854 }
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 return status;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
857 }
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 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
860 IDA::set_maxstep (realtype maxstep)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
861 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
862 if (IDASetMaxStep (mem, maxstep) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
863 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
864 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
865
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
866 void
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
867 IDA::set_initialstep (realtype initialstep)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
868 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
869 if (IDASetInitStep (mem, initialstep) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
870 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
871 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
872
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
873 void
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
874 IDA::set_maxorder (int maxorder)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
875 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
876 if (IDASetMaxOrd (mem, maxorder) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
877 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
878 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
879
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
880 void
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
881 IDA::print_stat (void)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
882 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
883 long int nsteps = 0, netfails = 0, nrevals = 0;
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
884
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
885 if (IDAGetNumSteps (mem, &nsteps) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
886 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
887
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
888 if (IDAGetNumErrTestFails (mem, &netfails) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
889 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
890
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
891 if (IDAGetNumResEvals (mem, &nrevals) != 0)
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
892 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
893
26000
97e63ba8a34c * __ode15__.cc (IDA::print_stat): Use octave_stdout instead of std::cout.
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
894 octave_stdout << nsteps << " successful steps\n";
97e63ba8a34c * __ode15__.cc (IDA::print_stat): Use octave_stdout instead of std::cout.
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
895 octave_stdout << netfails << " failed attempts\n";
97e63ba8a34c * __ode15__.cc (IDA::print_stat): Use octave_stdout instead of std::cout.
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
896 octave_stdout << nrevals << " function evaluations\n";
97e63ba8a34c * __ode15__.cc (IDA::print_stat): Use octave_stdout instead of std::cout.
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
897 // octave_stdout << " partial derivatives\n";
97e63ba8a34c * __ode15__.cc (IDA::print_stat): Use octave_stdout instead of std::cout.
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
898 // octave_stdout << " LU decompositions\n";
97e63ba8a34c * __ode15__.cc (IDA::print_stat): Use octave_stdout instead of std::cout.
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
899 // octave_stdout << " solutions of linear systems\n";
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
900 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
901
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
902 ColumnVector
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
903 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
904 double t, octave_function *ida_fc)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
905 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
906 octave_value_list tmp;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
907
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
908 try
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
909 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
910 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
911 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
912 catch (execution_exception& e)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
913 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
914 err_user_supplied_eval (e, "__ode15__");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
915 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
916
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
917 return tmp(0).vector_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
918 }
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 Matrix
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
921 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
922 double t, double cj, octave_function *ida_jc)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
923 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
924 octave_value_list tmp;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
925
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
926 try
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
927 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
928 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
929 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
930 catch (execution_exception& e)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
931 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
932 err_user_supplied_eval (e, "__ode15__");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
933 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
934
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
935 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
936 }
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 SparseMatrix
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
939 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
940 double t, double cj, octave_function *ida_jc)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
941 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
942 octave_value_list tmp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
943
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
944 try
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
945 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
946 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
947 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23588
diff changeset
948 catch (execution_exception& e)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
949 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
950 err_user_supplied_eval (e, "__ode15__");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
951 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
952
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
953 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
954 }
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 Matrix
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
957 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
958 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
959 return (*dfdy) + cj * (*dfdyp);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
960 }
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 SparseMatrix
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
963 ida_sparse_cell_jac (SparseMatrix *spdfdy, SparseMatrix *spdfdyp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
964 double cj)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
965 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
966 return (*spdfdy) + cj * (*spdfdyp);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
967 }
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 octave_value_list
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
970 do_ode15 (octave_function *ida_fcn,
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23432
diff changeset
971 const ColumnVector& tspan,
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
972 const int numt,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
973 const realtype t0,
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23432
diff changeset
974 const ColumnVector& y0,
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23432
diff changeset
975 const ColumnVector& yp0,
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23432
diff changeset
976 const octave_scalar_map& options)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
977 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
978 octave_value_list retval;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
979
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
980 // Create object
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
981 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
982
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
983 // Set Jacobian
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
984 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
985
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
986 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
987
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
988 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
989
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
990 Matrix ida_dfdy, ida_dfdyp, *dfdy, *dfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
991 SparseMatrix ida_spdfdy, ida_spdfdyp, *spdfdy, *spdfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
992 octave_function *ida_jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
993 Cell jaccell;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
994
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
995 if (havejac)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
996 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
997 if (havejacfun)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
998 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
999 ida_jac = options.getfield ("Jacobian").function_value ();
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1000
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1001 if (havejacsparse)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1002 dae.set_jacobian (ida_jac, ida_sparse_jac);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1003 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1004 dae.set_jacobian (ida_jac, ida_dense_jac);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1005 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1006 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1007 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1008 jaccell = options.getfield ("Jacobian").cell_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1009
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1010 if (havejacsparse)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1011 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1012 ida_spdfdy = jaccell(0).sparse_matrix_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1013 ida_spdfdyp = jaccell(1).sparse_matrix_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1014 spdfdy = &ida_spdfdy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1015 spdfdyp = &ida_spdfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1016 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
1017 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1018 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1019 {
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1020 ida_dfdy = jaccell(0).matrix_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1021 ida_dfdyp = jaccell(1).matrix_value ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1022 dfdy = &ida_dfdy;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1023 dfdyp = &ida_dfdyp;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1024 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
1025 }
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 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1028
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1029 // Initialize IDA
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1030 dae.initialize ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1031
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1032 // Set tolerances
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1033 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
1034
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1035 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
1036
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1037 if (haveabstolvec)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1038 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1039 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
1040
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1041 dae.set_tolerance (abs_tol, rel_tol);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1042 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1043 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1044 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1045 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
1046
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1047 dae.set_tolerance (abs_tol, rel_tol);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1048 }
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1049
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1050 //Set max step
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1051 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
1052
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1053 dae.set_maxstep (maxstep);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1054
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1055 //Set initial step
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23565
diff changeset
1056 if (! options.getfield("InitialStep").isempty ())
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1057 {
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1058 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
1059
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1060 dae.set_initialstep (initialstep);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1061 }
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 //Set max order FIXME: it doesn't work
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1064 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
1065
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1066 dae.set_maxorder (maxorder);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1067
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1068 //Set Refine
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1069 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
1070
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1071 bool haverefine = (refine > 1);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1072
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23433
diff changeset
1073 octave_function *output_fcn = nullptr;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1074 ColumnVector outputsel;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1075
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1076 // OutputFcn
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1077 bool haveoutputfunction
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1078 = options.getfield("haveoutputfunction").bool_value ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1079
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1080 if (haveoutputfunction)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1081 output_fcn = options.getfield("OutputFcn").function_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1082
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1083 // OutputSel
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1084 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
1085
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1086 if (haveoutputsel)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1087 outputsel = options.getfield("OutputSel").vector_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1088
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23433
diff changeset
1089 octave_function *event_fcn = nullptr;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1090
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1091 // Events
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1092 bool haveeventfunction
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1093 = options.getfield("haveeventfunction").bool_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1094
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1095 if (haveeventfunction)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1096 event_fcn = options.getfield("Events").function_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1097
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1098 // Set up linear solver
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1099 dae.set_up ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1100
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1101 // Integrate
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1102 retval = dae.integrate (numt, tspan, y0, yp0, refine,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1103 haverefine, haveoutputfunction,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1104 output_fcn, haveoutputsel, outputsel,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1105 haveeventfunction, event_fcn);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1106
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1107 // Statistics
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1108 bool havestats = options.getfield("havestats").bool_value ();
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1109
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1110 if (havestats)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1111 dae.print_stat ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1112
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1113 return retval;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1114 }
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1115 }
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1116 #endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1117
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1118
22913
69342e4f0dcf * __ode15__.cc: Don't check nargout.
John W. Eaton <jwe@octave.org>
parents: 22912
diff changeset
1119 DEFUN_DLD (__ode15__, args, ,
69342e4f0dcf * __ode15__.cc: Don't check nargout.
John W. Eaton <jwe@octave.org>
parents: 22912
diff changeset
1120 doc: /* -*- texinfo -*-
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23480
diff changeset
1121 @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
1122 Undocumented internal function.
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1123 @end deftypefn */)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1124 {
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 #if defined (HAVE_SUNDIALS)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1127
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1128 // Check number of parameters
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1129 int nargin = args.length ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1130
22913
69342e4f0dcf * __ode15__.cc: Don't check nargout.
John W. Eaton <jwe@octave.org>
parents: 22912
diff changeset
1131 if (nargin != 5)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1132 print_usage ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1133
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1134 // Check odefun
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23433
diff changeset
1135 octave_function *ida_fcn = nullptr;
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1136
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1137 octave_value f_arg = args(0);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1138
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1139 if (! f_arg.is_function_handle ())
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1140 error ("__ode15__: odefun must be a function handle");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1141
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1142 ida_fcn = f_arg.function_value ();
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1143
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1144 // Check input tspan
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1145 ColumnVector tspan
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1146 = 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
1147
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1148 int numt = tspan.numel ();
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1149
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1150 realtype t0 = tspan (0);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1151
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22903
diff changeset
1152 if (numt < 2)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1153 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
1154 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
1155 error ("__ode15__: TRANGE must be strictly monotonic");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1156
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1157 // input y0 and yp0
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1158 ColumnVector y0
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1159 = 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
1160
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1161 ColumnVector yp0
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1162 = 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
1163
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 if (y0.numel () != yp0.numel ())
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1166 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
1167 else if (y0.numel () < 1)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1168 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
1169
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1170
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23577
diff changeset
1171 if (! args(4).isstruct ())
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1172 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
1173
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1174 octave_scalar_map options
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1175 = 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
1176
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1177
22917
c1ac4ac3ebbc * __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 22915
diff changeset
1178 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
1179
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1180
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1181 #else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1182
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1183 octave_unused_parameter (args);
22911
82551783527f * __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
1184
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1185 err_disabled_feature ("__ode15__", "sundials_ida, sundials_nvecserial");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1186
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1187 #endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
1188 }