annotate libinterp/dldfcn/__ode15__.cc @ 25098:5dce8aa80652 stable

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