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