Mercurial > octave
annotate libinterp/dldfcn/__ode15__.cc @ 29163:8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
* GLCanvas.cc, interpreter-qobject.cc, file-editor-tab.cc,
octave-qscintilla.cc, octave-qobject.cc, Cell.cc, __eigs__.cc,
__magick_read__.cc, __qp__.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc,
file-io.cc, graphics.cc, graphics.in.h, input.cc, interpreter.cc,
ls-mat-ascii.cc, lsode.cc, oct-handle.h, oct-map.cc, quad.cc, rand.cc,
sparse.cc, sub2ind.cc, toplev.cc, utils.cc, __init_gnuplot__.cc, __ode15__.cc,
cdef-object.cc, ov-base-diag.cc, ov-base-mat.cc, ov-base-sparse.cc,
ov-base.cc, ov-fcn-handle.cc, ov-java.cc, ov-perm.cc, ov-range.cc,
ov-re-diag.cc, ov-str-mat.cc, ov.cc, pt-assign.cc, pt-eval.cc, pt-idx.cc,
pt-jit.cc, pt.cc, Array-util.cc, randmtzig.cc:
Update naming conventions for exceptions to use initial letter of exception
type. For example, "execution_exception" is named "ee", "index_exception" is
"ie". Catch "const" exceptions where possible.
* gzip.cc: Add block to catch and throw interrupt_exceptions before having
a catch block "(...)" for everything else.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 08 Dec 2020 13:25:03 -0800 |
parents | b1b09b88585a |
children | 7bf91e98bfc6 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 2016-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
25 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
27 # include "config.h" |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
28 #endif |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
29 |
22911
82551783527f
* __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents:
22910
diff
changeset
|
30 #include "dColVector.h" |
82551783527f
* __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents:
22910
diff
changeset
|
31 #include "dMatrix.h" |
82551783527f
* __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents:
22910
diff
changeset
|
32 #include "dSparse.h" |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
33 #include "f77-fcn.h" |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28741
diff
changeset
|
34 #include "lo-utils.h" |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
35 |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
23022
diff
changeset
|
36 #include "Cell.h" |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
37 #include "defun-dld.h" |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
38 #include "error.h" |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
23022
diff
changeset
|
39 #include "errwarn.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
23022
diff
changeset
|
40 #include "oct-map.h" |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
41 #include "ov.h" |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
23022
diff
changeset
|
42 #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
|
43 #include "pager.h" |
22911
82551783527f
* __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents:
22910
diff
changeset
|
44 #include "parse.h" |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
45 |
22911
82551783527f
* __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents:
22910
diff
changeset
|
46 #if defined (HAVE_SUNDIALS) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
47 |
26898
d94876e7a0aa
Remove calls to deprecated sundials functions.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26897
diff
changeset
|
48 # if defined (HAVE_NVECTOR_NVECTOR_SERIAL_H) |
d94876e7a0aa
Remove calls to deprecated sundials functions.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26897
diff
changeset
|
49 # include <nvector/nvector_serial.h> |
25098
5dce8aa80652
configure: disable SUNDIALS if the IDADENSE API is not found (bug #52475)
Mike Miller <mtmiller@octave.org>
parents:
25054
diff
changeset
|
50 # endif |
5dce8aa80652
configure: disable SUNDIALS if the IDADENSE API is not found (bug #52475)
Mike Miller <mtmiller@octave.org>
parents:
25054
diff
changeset
|
51 |
26898
d94876e7a0aa
Remove calls to deprecated sundials functions.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26897
diff
changeset
|
52 # if defined (HAVE_IDA_IDA_H) |
d94876e7a0aa
Remove calls to deprecated sundials functions.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26897
diff
changeset
|
53 # include <ida/ida.h> |
26903
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
54 # elif defined (HAVE_IDA_H) |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
55 # include <ida.h> |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
56 # endif |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
57 # if defined (HAVE_IDA_IDA_DIRECT_H) |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
58 # include <ida/ida_direct.h> |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
59 # elif defined (HAVE_IDA_DIRECT_H) |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
60 # include <ida_direct.h> |
26894
ee6300e77c92
Update detection of sundials in the build system (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26893
diff
changeset
|
61 # endif |
ee6300e77c92
Update detection of sundials in the build system (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26893
diff
changeset
|
62 |
ee6300e77c92
Update detection of sundials in the build system (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26893
diff
changeset
|
63 # 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
|
64 # 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
|
65 # endif |
305cdc1d444b
* __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents:
22919
diff
changeset
|
66 |
26894
ee6300e77c92
Update detection of sundials in the build system (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26893
diff
changeset
|
67 # 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
|
68 # 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
|
69 # include <klu.h> |
a1acd11bad19
Directly include klu.h in __ode15__.cc (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26894
diff
changeset
|
70 # endif |
a1acd11bad19
Directly include klu.h in __ode15__.cc (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26894
diff
changeset
|
71 # 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
|
72 # 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
|
73 # endif |
a1acd11bad19
Directly include klu.h in __ode15__.cc (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26894
diff
changeset
|
74 # 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
|
75 # 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
|
76 # endif |
a1acd11bad19
Directly include klu.h in __ode15__.cc (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26894
diff
changeset
|
77 # 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
|
78 # 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
|
79 # endif |
26894
ee6300e77c92
Update detection of sundials in the build system (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26893
diff
changeset
|
80 # 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
|
81 # endif |
ee6300e77c92
Update detection of sundials in the build system (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26893
diff
changeset
|
82 |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
83 namespace octave |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
84 { |
26903
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
85 # if ! defined (HAVE_IDASETJACFN) && defined (HAVE_IDADLSSETJACFN) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
86 static inline int |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
87 IDASetJacFn (void *ida_mem, IDADlsJacFn jac) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
88 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
89 return IDADlsSetJacFn (ida_mem, jac); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
90 } |
26903
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
91 # endif |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
92 |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
93 # if ! defined (HAVE_IDASETLINEARSOLVER) && defined (HAVE_IDADLSSETLINEARSOLVER) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
94 static inline int |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
95 IDASetLinearSolver (void *ida_mem, SUNLinearSolver LS, SUNMatrix A) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
96 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
97 return IDADlsSetLinearSolver (ida_mem, LS, A); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
98 } |
26903
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
99 # endif |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
100 |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
101 # if ! defined (HAVE_SUNLINSOL_DENSE) && defined (HAVE_SUNDENSELINEARSOLVER) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
102 static inline SUNLinearSolver |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
103 SUNLinSol_Dense (N_Vector y, SUNMatrix A) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
104 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
105 return SUNDenseLinearSolver (y, A); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
106 } |
26903
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
107 # endif |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
108 |
26909
5042a568771a
don't disable all of sundials if including sunlinsol_klu.h fails (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26907
diff
changeset
|
109 # if defined (HAVE_SUNDIALS_SUNLINSOL_KLU) |
5042a568771a
don't disable all of sundials if including sunlinsol_klu.h fails (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26907
diff
changeset
|
110 # if ! defined (HAVE_SUNLINSOL_KLU) && defined (HAVE_SUNKLU) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
111 static inline SUNLinearSolver |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
112 SUNLinSol_KLU (N_Vector y, SUNMatrix A) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
113 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
114 return SUNKLU (y, A); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
115 } |
26909
5042a568771a
don't disable all of sundials if including sunlinsol_klu.h fails (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26907
diff
changeset
|
116 # endif |
26903
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
117 # endif |
73b141d5a888
improve configure checks for sundials (bug #55911)
John W. Eaton <jwe@octave.org>
parents:
26898
diff
changeset
|
118 |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
119 static inline realtype * |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
120 nv_data_s (N_Vector& v) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
121 { |
28741
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
122 # if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
123 // Disable warning from GCC about old-style casts in Sundials |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
124 // macro expansions. Do this in a function so that this |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
125 // diagnostic may still be enabled for the rest of the file. |
28741
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
126 # pragma GCC diagnostic push |
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
127 # pragma GCC diagnostic ignored "-Wold-style-cast" |
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
128 # endif |
22915
7766e3ef6c69
* __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents:
22914
diff
changeset
|
129 |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
130 return NV_DATA_S (v); |
23085
dffa2b8c9482
maint: strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23075
diff
changeset
|
131 |
28741
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
132 # if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
133 // Restore prevailing warning state for remainder of the file. |
28741
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
134 # pragma GCC diagnostic pop |
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
135 # endif |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26909
diff
changeset
|
136 } |
22915
7766e3ef6c69
* __ode15__.cc: Avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents:
22914
diff
changeset
|
137 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
138 class IDA |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
139 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
140 public: |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
141 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
142 typedef |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
143 ColumnVector (*DAERHSFuncIDA) (const ColumnVector& x, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
144 const ColumnVector& xdot, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
145 realtype t, const octave_value& idaf); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
146 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
147 typedef |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
148 Matrix (*DAEJacFuncDense) (const ColumnVector& x, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
149 const ColumnVector& xdot, realtype t, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
150 realtype cj, const octave_value& idaj); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
151 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
152 typedef |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
153 SparseMatrix (*DAEJacFuncSparse) (const ColumnVector& x, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
154 const ColumnVector& xdot, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
155 realtype t, realtype cj, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
156 const octave_value& idaj); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
157 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
158 typedef |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
159 Matrix (*DAEJacCellDense) (Matrix *dfdy, Matrix *dfdyp, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
160 realtype cj); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
161 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
162 typedef |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
163 SparseMatrix (*DAEJacCellSparse) (SparseMatrix *dfdy, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
164 SparseMatrix *dfdyp, realtype cj); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
165 |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
166 //Default |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
167 IDA (void) |
27182 | 168 : m_t0 (0.0), m_y0 (), m_yp0 (), m_havejac (false), m_havejacfun (false), |
169 m_havejacsparse (false), m_mem (nullptr), m_num (), m_ida_fun (), | |
170 m_ida_jac (), m_dfdy (nullptr), m_dfdyp (nullptr), m_spdfdy (nullptr), | |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
171 m_spdfdyp (nullptr), m_fun (nullptr), m_jacfun (nullptr), |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
172 m_jacspfun (nullptr), m_jacdcell (nullptr), m_jacspcell (nullptr), |
27182 | 173 m_sunJacMatrix (nullptr), m_sunLinearSolver (nullptr) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
174 { } |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
175 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
176 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
177 IDA (realtype t, ColumnVector y, ColumnVector yp, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
178 const octave_value& ida_fcn, DAERHSFuncIDA daefun) |
27182 | 179 : m_t0 (t), m_y0 (y), m_yp0 (yp), m_havejac (false), m_havejacfun (false), |
180 m_havejacsparse (false), m_mem (nullptr), m_num (), m_ida_fun (ida_fcn), | |
181 m_ida_jac (), m_dfdy (nullptr), m_dfdyp (nullptr), m_spdfdy (nullptr), | |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
182 m_spdfdyp (nullptr), m_fun (daefun), m_jacfun (nullptr), |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
183 m_jacspfun (nullptr), m_jacdcell (nullptr), m_jacspcell (nullptr), |
27182 | 184 m_sunJacMatrix (nullptr), m_sunLinearSolver (nullptr) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
185 { } |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
186 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
187 |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
188 ~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
|
189 { |
27182 | 190 IDAFree (&m_mem); |
191 SUNLinSolFree (m_sunLinearSolver); | |
192 SUNMatDestroy (m_sunJacMatrix); | |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
193 } |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
194 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
195 IDA& |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
196 set_jacobian (const octave_value& jac, DAEJacFuncDense j) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
197 { |
27182 | 198 m_jacfun = j; |
199 m_ida_jac = jac; | |
200 m_havejac = true; | |
201 m_havejacfun = true; | |
202 m_havejacsparse = false; | |
203 | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
204 return *this; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
205 } |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
206 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
207 IDA& |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
208 set_jacobian (const octave_value& jac, DAEJacFuncSparse j) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
209 { |
27182 | 210 m_jacspfun = j; |
211 m_ida_jac = jac; | |
212 m_havejac = true; | |
213 m_havejacfun = true; | |
214 m_havejacsparse = true; | |
215 | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
216 return *this; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
217 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
218 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
219 IDA& |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
220 set_jacobian (Matrix *dy, Matrix *dyp, DAEJacCellDense j) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
221 { |
27182 | 222 m_jacdcell = j; |
223 m_dfdy = dy; | |
224 m_dfdyp = dyp; | |
225 m_havejac = true; | |
226 m_havejacfun = false; | |
227 m_havejacsparse = false; | |
228 | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
229 return *this; |
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 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
232 IDA& |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
233 set_jacobian (SparseMatrix *dy, SparseMatrix *dyp, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
234 DAEJacCellSparse j) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
235 { |
27182 | 236 m_jacspcell = j; |
237 m_spdfdy = dy; | |
238 m_spdfdyp = dyp; | |
239 m_havejac = true; | |
240 m_havejacfun = false; | |
241 m_havejacsparse = true; | |
242 | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
243 return *this; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
244 } |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
245 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
246 void set_userdata (void); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
247 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
248 void initialize (void); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
249 |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
250 static ColumnVector NVecToCol (N_Vector& v, octave_f77_int_type n); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
251 |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
252 static N_Vector ColToNVec (const ColumnVector& data, octave_f77_int_type n); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
253 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
254 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
|
255 set_up (const ColumnVector& y); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
256 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
257 void |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
258 set_tolerance (ColumnVector& abstol, realtype reltol); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
259 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
260 void |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
261 set_tolerance (realtype abstol, realtype reltol); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
262 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
263 static int |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
264 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
|
265 N_Vector rr, void *user_data); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
266 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
267 void |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
268 resfun_impl (realtype t, N_Vector& yy, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
269 N_Vector& yyp, N_Vector& rr); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
270 static int |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
271 jacdense (realtype t, realtype cj, N_Vector yy, N_Vector yyp, |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
272 N_Vector, SUNMatrix JJ, void *user_data, N_Vector, |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
273 N_Vector, N_Vector) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
274 { |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
275 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
|
276 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
|
277 return 0; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
278 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
279 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
280 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
|
281 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
|
282 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
|
283 |
26894
ee6300e77c92
Update detection of sundials in the build system (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26893
diff
changeset
|
284 # if defined (HAVE_SUNDIALS_SUNLINSOL_KLU) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
285 static int |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
286 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
|
287 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
|
288 N_Vector, N_Vector) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
289 { |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
290 IDA *self = static_cast <IDA *> (user_data); |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
291 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
|
292 return 0; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
293 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
294 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
295 void |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
296 jacsparse_impl (realtype t, realtype cj, |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
297 N_Vector& yy, N_Vector& yyp, SUNMatrix& Jac); |
26898
d94876e7a0aa
Remove calls to deprecated sundials functions.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26897
diff
changeset
|
298 # endif |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
299 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
300 void set_maxstep (realtype maxstep); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
301 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
302 void set_initialstep (realtype initialstep); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
303 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
304 bool |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
305 interpolate (octave_idx_type& cont, Matrix& output, ColumnVector& tout, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
306 int refine, realtype tend, bool haveoutputfcn, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
307 bool haveoutputsel, const octave_value& output_fcn, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
308 ColumnVector& outputsel, bool haveeventfunction, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
309 const octave_value& event_fcn, ColumnVector& te, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
310 Matrix& ye, ColumnVector& ie, ColumnVector& oldval, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
311 ColumnVector& oldisterminal, ColumnVector& olddir, |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
312 octave_idx_type& temp, ColumnVector& yold); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
313 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
314 bool |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
315 outputfun (const octave_value& output_fcn, bool haveoutputsel, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
316 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
|
317 ColumnVector& outputsel, const std::string& flag); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
318 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
319 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
320 bool |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
321 event (const octave_value& event_fcn, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
322 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
|
323 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
|
324 const ColumnVector& yp, ColumnVector& oldval, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
325 ColumnVector& oldisterminal, ColumnVector& olddir, |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
326 octave_idx_type cont, octave_idx_type& temp, realtype told, |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
327 ColumnVector& yold); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
328 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
329 void set_maxorder (int maxorder); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
330 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
331 octave_value_list |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
332 integrate (const octave_idx_type numt, const ColumnVector& tt, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
333 const ColumnVector& y0, const ColumnVector& yp0, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
334 const int refine, bool haverefine, bool haveoutputfcn, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
335 const octave_value& output_fcn, bool haveoutputsel, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
336 ColumnVector& outputsel, bool haveeventfunction, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
337 const octave_value& event_fcn); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
338 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
339 void print_stat (void); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
340 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
341 private: |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
342 |
27182 | 343 realtype m_t0; |
344 ColumnVector m_y0; | |
345 ColumnVector m_yp0; | |
346 bool m_havejac; | |
347 bool m_havejacfun; | |
348 bool m_havejacsparse; | |
349 void *m_mem; | |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
350 octave_f77_int_type m_num; |
27182 | 351 octave_value m_ida_fun; |
352 octave_value m_ida_jac; | |
353 Matrix *m_dfdy; | |
354 Matrix *m_dfdyp; | |
355 SparseMatrix *m_spdfdy; | |
356 SparseMatrix *m_spdfdyp; | |
357 DAERHSFuncIDA m_fun; | |
358 DAEJacFuncDense m_jacfun; | |
359 DAEJacFuncSparse m_jacspfun; | |
360 DAEJacCellDense m_jacdcell; | |
361 DAEJacCellSparse m_jacspcell; | |
362 SUNMatrix m_sunJacMatrix; | |
363 SUNLinearSolver m_sunLinearSolver; | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
364 }; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
365 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
366 int |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
367 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
|
368 void *user_data) |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
369 { |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
370 IDA *self = static_cast <IDA *> (user_data); |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
371 self->resfun_impl (t, yy, yyp, rr); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
372 return 0; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
373 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
374 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
375 void |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
376 IDA::resfun_impl (realtype t, N_Vector& yy, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
377 N_Vector& yyp, N_Vector& rr) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
378 { |
27182 | 379 ColumnVector y = IDA::NVecToCol (yy, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
380 |
27182 | 381 ColumnVector yp = IDA::NVecToCol (yyp, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
382 |
27182 | 383 ColumnVector res = (*m_fun) (y, yp, t, m_ida_fun); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
384 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
385 realtype *puntrr = nv_data_s (rr); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
386 |
27182 | 387 for (octave_idx_type i = 0; i < m_num; i++) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
388 puntrr[i] = res(i); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
389 } |
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 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
|
392 IDA::set_up (const ColumnVector& y) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
393 { |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
394 N_Vector yy = ColToNVec (y, m_num); |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
395 |
27182 | 396 if (m_havejacsparse) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
397 { |
26898
d94876e7a0aa
Remove calls to deprecated sundials functions.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26897
diff
changeset
|
398 # if defined (HAVE_SUNDIALS_SUNLINSOL_KLU) |
28739
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
399 # if defined (HAVE_SUNSPARSEMATRIX_REALLOCATE) |
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
400 // Initially allocate memory for 0 entries. We will reallocate when we |
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
401 // get the Jacobian matrix from the user and know the actual number of |
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
402 // entries. |
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
403 m_sunJacMatrix = SUNSparseMatrix (m_num, m_num, 0, CSC_MAT); |
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
404 # else |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28849
diff
changeset
|
405 if (math::int_multiply_overflow (m_num, m_num)) |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28741
diff
changeset
|
406 error ("Unable to allocate memory for sparse Jacobian"); |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28741
diff
changeset
|
407 |
27182 | 408 m_sunJacMatrix = SUNSparseMatrix (m_num, m_num, m_num*m_num, CSC_MAT); |
28739
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
409 # endif |
27182 | 410 if (! m_sunJacMatrix) |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
411 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
|
412 |
27182 | 413 m_sunLinearSolver = SUNLinSol_KLU (yy, m_sunJacMatrix); |
414 if (! m_sunLinearSolver) | |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
415 error ("Unable to create KLU sparse solver"); |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
416 |
27182 | 417 if (IDASetLinearSolver (m_mem, m_sunLinearSolver, m_sunJacMatrix)) |
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 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
|
419 |
27182 | 420 IDASetJacFn (m_mem, IDA::jacsparse); |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
421 |
23022
305cdc1d444b
* __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents:
22919
diff
changeset
|
422 # else |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
423 error ("SUNDIALS SUNLINSOL KLU was unavailable or disabled when " |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
424 "Octave was built"); |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
425 |
23022
305cdc1d444b
* __ode15__.cc: Disable sparse jacobian handling if IDAKLU is missing.
John W. Eaton <jwe@octave.org>
parents:
22919
diff
changeset
|
426 # 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
|
427 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
428 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
429 else |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
430 { |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
431 |
27182 | 432 m_sunJacMatrix = SUNDenseMatrix (m_num, m_num); |
433 if (! m_sunJacMatrix) | |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
434 error ("Unable to create dense Jacobian for Sundials"); |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
435 |
27182 | 436 m_sunLinearSolver = SUNLinSol_Dense (yy, m_sunJacMatrix); |
437 if (! m_sunLinearSolver) | |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
438 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
|
439 |
27182 | 440 if (IDASetLinearSolver (m_mem, m_sunLinearSolver, m_sunJacMatrix)) |
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 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
|
442 |
27182 | 443 if (m_havejac && IDASetJacFn (m_mem, IDA::jacdense) != 0) |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
444 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
|
445 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
446 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
447 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
448 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
449 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
|
450 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
|
451 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
|
452 |
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
453 { |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
454 octave_f77_int_type Neq = NV_LENGTH_S (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
|
455 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
456 ColumnVector y = NVecToCol (yy, Neq); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
457 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
458 ColumnVector yp = NVecToCol (yyp, Neq); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
459 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
460 Matrix jac; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
461 |
27182 | 462 if (m_havejacfun) |
463 jac = (*m_jacfun) (y, yp, t, cj, m_ida_jac); | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
464 else |
27182 | 465 jac = (*m_jacdcell) (m_dfdy, m_dfdyp, cj); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
466 |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
467 octave_f77_int_type num_jac = to_f77_int (jac.numel ()); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
468 std::copy (jac.fortran_vec (), |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
469 jac.fortran_vec () + num_jac, |
27182 | 470 SUNDenseMatrix_Data (JJ)); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
471 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
472 |
26894
ee6300e77c92
Update detection of sundials in the build system (bug #52475).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26893
diff
changeset
|
473 # if defined (HAVE_SUNDIALS_SUNLINSOL_KLU) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
474 void |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
475 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
|
476 SUNMatrix& Jac) |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
477 |
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
478 { |
27182 | 479 ColumnVector y = NVecToCol (yy, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
480 |
27182 | 481 ColumnVector yp = NVecToCol (yyp, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
482 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
483 SparseMatrix jac; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
484 |
27182 | 485 if (m_havejacfun) |
486 jac = (*m_jacspfun) (y, yp, t, cj, m_ida_jac); | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
487 else |
27182 | 488 jac = (*m_jacspcell) (m_spdfdy, m_spdfdyp, cj); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
489 |
28741
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
490 # if defined (HAVE_SUNSPARSEMATRIX_REALLOCATE) |
28739
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
491 octave_f77_int_type nnz = to_f77_int (jac.nnz ()); |
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
492 if (nnz > SUNSparseMatrix_NNZ (Jac)) |
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
493 { |
28741
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
494 // Allocate memory for sparse Jacobian defined in user function. |
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
495 // This will always be required at least once since we set the number |
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
496 // of non-zero elements to zero initially. |
28739
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
497 if (SUNSparseMatrix_Reallocate (Jac, nnz)) |
28741
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
498 error ("Unable to allocate sufficient memory for IDA sparse matrix"); |
28739
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
499 } |
28741
2cd4a32cbc4b
maint: Change "#if" indentation for consistency in __ode15__.cc.
Rik <rik@octave.org>
parents:
28739
diff
changeset
|
500 # endif |
28739
3eb2fab71028
Allocate memory for Jacobian in __ode15__ more efficiently (bug #55905).
Bill Greene <w.h.greene@gmail.com>
parents:
28716
diff
changeset
|
501 |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
502 SUNMatZero_Sparse (Jac); |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
503 // We have to use "sunindextype *" here but still need to check that |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
504 // conversion of each element to "octave_f77_int_type" is save. |
28709
9dc9f15dac64
Back out changeset 0c9a5eae6c27
Markus Mützel <markus.muetzel@gmx.de>
parents:
28706
diff
changeset
|
505 sunindextype *colptrs = SUNSparseMatrix_IndexPointers (Jac); |
9dc9f15dac64
Back out changeset 0c9a5eae6c27
Markus Mützel <markus.muetzel@gmx.de>
parents:
28706
diff
changeset
|
506 sunindextype *rowvals = SUNSparseMatrix_IndexValues (Jac); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
507 |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
508 for (octave_f77_int_type i = 0; i < m_num + 1; i++) |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
509 colptrs[i] = to_f77_int (jac.cidx (i)); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
510 |
26893
25284d620919
Update DAE/IDE solvers to work with SUNDIALS 3 (bug #52475).
Bill Greene <w.h.greene@gmail.com>
parents:
26392
diff
changeset
|
511 double *d = SUNSparseMatrix_Data (Jac); |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
512 for (octave_f77_int_type i = 0; i < to_f77_int (jac.nnz ()); i++) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
513 { |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
514 rowvals[i] = to_f77_int (jac.ridx (i)); |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
515 d[i] = jac.data (i); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
516 } |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
517 } |
26898
d94876e7a0aa
Remove calls to deprecated sundials functions.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26897
diff
changeset
|
518 # endif |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
519 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
520 ColumnVector |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
521 IDA::NVecToCol (N_Vector& v, octave_f77_int_type n) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
522 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
523 ColumnVector data (n); |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
524 realtype *punt = nv_data_s (v); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
525 |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
526 for (octave_f77_int_type i = 0; i < n; i++) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
527 data(i) = punt[i]; |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
528 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
529 return data; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
530 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
531 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
532 N_Vector |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
533 IDA::ColToNVec (const ColumnVector& data, octave_f77_int_type n) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
534 { |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
535 N_Vector v = N_VNew_Serial (n); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
536 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
537 realtype *punt = nv_data_s (v); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
538 |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
539 for (octave_f77_int_type i = 0; i < n; i++) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
540 punt[i] = data(i); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
541 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
542 return v; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
543 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
544 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
545 void |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
546 IDA::set_userdata (void) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
547 { |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
548 void *userdata = this; |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
549 |
27182 | 550 if (IDASetUserData (m_mem, userdata) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
551 error ("User data not set"); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
552 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
553 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
554 void |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
555 IDA::initialize (void) |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
556 { |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
557 m_num = to_f77_int (m_y0.numel ()); |
27182 | 558 m_mem = IDACreate (); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
559 |
27182 | 560 N_Vector yy = ColToNVec (m_y0, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
561 |
27182 | 562 N_Vector yyp = ColToNVec (m_yp0, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
563 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
564 IDA::set_userdata (); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
565 |
27182 | 566 if (IDAInit (m_mem, IDA::resfun, m_t0, yy, yyp) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
567 error ("IDA not initialized"); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
568 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
569 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
570 void |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
571 IDA::set_tolerance (ColumnVector& abstol, realtype reltol) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
572 { |
27182 | 573 N_Vector abs_tol = ColToNVec (abstol, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
574 |
27182 | 575 if (IDASVtolerances (m_mem, reltol, abs_tol) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
576 error ("IDA: Tolerance not set"); |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
577 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
578 N_VDestroy_Serial (abs_tol); |
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 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
581 void |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
582 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
|
583 { |
27182 | 584 if (IDASStolerances (m_mem, reltol, abstol) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
585 error ("IDA: Tolerance not set"); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
586 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
587 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
588 octave_value_list |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
589 IDA::integrate (const octave_idx_type numt, const ColumnVector& tspan, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
590 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
|
591 const int refine, bool haverefine, bool haveoutputfcn, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
592 const octave_value& output_fcn, bool haveoutputsel, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
593 ColumnVector& outputsel, bool haveeventfunction, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
594 const octave_value& event_fcn) |
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 // Set up output |
27182 | 597 ColumnVector tout, yout (m_num), ypout (m_num), ysel (outputsel.numel ()); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
598 ColumnVector ie, te, oldval, oldisterminal, olddir; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
599 Matrix output, ye; |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
600 octave_idx_type cont = 0, temp = 0; |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
601 bool status = 0; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
602 std::string string = ""; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
603 ColumnVector yold = y; |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
604 |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
605 realtype tsol = tspan(0); |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
606 realtype tend = tspan(numt-1); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
607 |
27182 | 608 N_Vector yyp = ColToNVec (yp, m_num); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
609 |
27182 | 610 N_Vector yy = ColToNVec (y, m_num); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
611 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
612 // Initialize OutputFcn |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
613 if (haveoutputfcn) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
614 status = IDA::outputfun (output_fcn, haveoutputsel, y, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
615 tsol, tend, outputsel, "init"); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
616 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
617 // Initialize Events |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
618 if (haveeventfunction) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
619 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
|
620 "init", yp, oldval, oldisterminal, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
621 olddir, cont, temp, tsol, yold); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
622 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
623 if (numt > 2) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
624 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
625 // First output value |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
626 tout.resize (numt); |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
627 tout(0) = tsol; |
27182 | 628 output.resize (numt, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
629 |
27182 | 630 for (octave_idx_type i = 0; i < m_num; i++) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
631 output.elem (0, i) = y.elem (i); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
632 |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
633 //Main loop |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
634 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
|
635 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
636 // IDANORMAL already interpolates tspan(j) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
637 |
27182 | 638 if (IDASolve (m_mem, tspan (j), &tsol, yy, yyp, IDA_NORMAL) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
639 error ("IDASolve failed"); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
640 |
27182 | 641 yout = NVecToCol (yy, m_num); |
642 ypout = NVecToCol (yyp, m_num); | |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
643 tout(j) = tsol; |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
644 |
27182 | 645 for (octave_idx_type i = 0; i < m_num; i++) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
646 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
|
647 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
648 if (haveoutputfcn) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
649 status = IDA::outputfun (output_fcn, haveoutputsel, yout, tsol, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
650 tend, outputsel, string); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
651 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
652 if (haveeventfunction) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
653 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
|
654 string, ypout, oldval, oldisterminal, |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
655 olddir, j, temp, tout(j-1), yold); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
656 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
657 // 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
|
658 if (status == 1) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
659 { |
27182 | 660 output.resize (j + 1, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
661 tout.resize (j + 1); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
662 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
663 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
664 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
665 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
666 else // numel (tspan) == 2 |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
667 { |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
668 // First output value |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
669 tout.resize (1); |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
670 tout(0) = tsol; |
27182 | 671 output.resize (1, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
672 |
27182 | 673 for (octave_idx_type i = 0; i < m_num; i++) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
674 output.elem (0, i) = y.elem (i); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
675 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
676 bool posdirection = (tend > tsol); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
677 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
678 //main loop |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
679 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
|
680 || (posdirection == 0 && tsol > tend)) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
681 && status == 0) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
682 { |
27182 | 683 if (IDASolve (m_mem, tend, &tsol, yy, yyp, IDA_ONE_STEP) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
684 error ("IDASolve failed"); |
22901
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 if (haverefine) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
687 status = IDA::interpolate (cont, output, tout, refine, tend, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
688 haveoutputfcn, haveoutputsel, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
689 output_fcn, outputsel, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
690 haveeventfunction, event_fcn, te, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
691 ye, ie, oldval, oldisterminal, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
692 olddir, temp, yold); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
693 |
27182 | 694 ypout = NVecToCol (yyp, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
695 cont += 1; |
27182 | 696 output.resize (cont + 1, m_num); // This may be not efficient |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
697 tout.resize (cont + 1); |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
698 tout(cont) = tsol; |
27182 | 699 yout = NVecToCol (yy, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
700 |
27182 | 701 for (octave_idx_type i = 0; i < m_num; i++) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
702 output.elem (cont, i) = yout.elem (i); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
703 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
704 if (haveoutputfcn && ! haverefine && tout(cont) < tend) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
705 status = IDA::outputfun (output_fcn, haveoutputsel, yout, tsol, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
706 tend, outputsel, string); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
707 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
708 if (haveeventfunction && ! haverefine && tout(cont) < tend) |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
709 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
|
710 string, ypout, oldval, oldisterminal, |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
711 olddir, cont, temp, tout(cont-1), yold); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
712 } |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
713 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
714 if (status == 0) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
715 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
716 // Interpolate in tend |
27182 | 717 N_Vector dky = N_VNew_Serial (m_num); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
718 |
27182 | 719 if (IDAGetDky (m_mem, tend, 0, dky) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
720 error ("IDA failed to interpolate y"); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
721 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
722 tout(cont) = tend; |
27182 | 723 yout = NVecToCol (dky, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
724 |
27182 | 725 for (octave_idx_type i = 0; i < m_num; i++) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
726 output.elem (cont, i) = yout.elem (i); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
727 |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
728 // Plot final value |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
729 if (haveoutputfcn) |
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 status = IDA::outputfun (output_fcn, haveoutputsel, yout, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
732 tend, tend, outputsel, string); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
733 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
734 // Events during last step |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
735 if (haveeventfunction) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
736 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
|
737 string, ypout, oldval, oldisterminal, |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
738 olddir, cont, temp, tout(cont-1), |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
739 yold); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
740 } |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
741 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
742 N_VDestroy_Serial (dky); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
743 } |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
744 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
745 // Cleanup plotter |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
746 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
|
747 outputsel, "done"); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
748 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
749 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
750 |
29039
1aa69571a313
Use 1-based indexing for "ie" variable in ode15i/s (bug #59063).
Rik <rik@octave.org>
parents:
28952
diff
changeset
|
751 // Index of Events (ie) variable must use 1-based indexing |
1aa69571a313
Use 1-based indexing for "ie" variable in ode15i/s (bug #59063).
Rik <rik@octave.org>
parents:
28952
diff
changeset
|
752 return ovl (tout, output, te, ye, ie + 1.0); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
753 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
754 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
755 bool |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
756 IDA::event (const octave_value& event_fcn, |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
757 ColumnVector& te, Matrix& ye, ColumnVector& ie, realtype tsol, |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
758 const ColumnVector& y, const std::string& flag, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
759 const ColumnVector& yp, ColumnVector& oldval, |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
760 ColumnVector& oldisterminal, ColumnVector& olddir, |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
761 octave_idx_type cont, octave_idx_type& temp, realtype told, |
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
762 ColumnVector& yold) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
763 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
764 bool status = 0; |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
765 |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
766 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
|
767 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
768 // 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
|
769 // temp is the number of events registered |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
770 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
771 if (flag == "init") |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
772 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23588
diff
changeset
|
773 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
|
774 oldval = output(0).vector_value (); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
775 oldisterminal = output(1).vector_value (); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
776 olddir = output(2).vector_value (); |
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 else if (flag == "") |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
779 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
780 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
|
781 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
|
782 ColumnVector val = output(0).vector_value (); |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
783 ColumnVector isterminal = output(1).vector_value (); |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
784 ColumnVector dir = output(2).vector_value (); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
785 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
786 // Get the index of the changed values |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
787 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
|
788 { |
29060
b1b09b88585a
ode15: Detect time events when time is a multiple of the output step size (bug #59063).
Markus Meisinger <chloros2@gmx.de>
parents:
29039
diff
changeset
|
789 // Check for sign change and whether a rising / falling edge |
b1b09b88585a
ode15: Detect time events when time is a multiple of the output step size (bug #59063).
Markus Meisinger <chloros2@gmx.de>
parents:
29039
diff
changeset
|
790 // either passes through zero or detaches from zero (bug #59063) |
b1b09b88585a
ode15: Detect time events when time is a multiple of the output step size (bug #59063).
Markus Meisinger <chloros2@gmx.de>
parents:
29039
diff
changeset
|
791 if ((dir(i) != -1 |
b1b09b88585a
ode15: Detect time events when time is a multiple of the output step size (bug #59063).
Markus Meisinger <chloros2@gmx.de>
parents:
29039
diff
changeset
|
792 && ((val(i) >= 0 && oldval(i) < 0) |
b1b09b88585a
ode15: Detect time events when time is a multiple of the output step size (bug #59063).
Markus Meisinger <chloros2@gmx.de>
parents:
29039
diff
changeset
|
793 || (val(i) > 0 && oldval(i) <= 0))) // increasing |
b1b09b88585a
ode15: Detect time events when time is a multiple of the output step size (bug #59063).
Markus Meisinger <chloros2@gmx.de>
parents:
29039
diff
changeset
|
794 || (dir(i) != 1 |
b1b09b88585a
ode15: Detect time events when time is a multiple of the output step size (bug #59063).
Markus Meisinger <chloros2@gmx.de>
parents:
29039
diff
changeset
|
795 && ((val(i) <= 0 && oldval(i) > 0) |
b1b09b88585a
ode15: Detect time events when time is a multiple of the output step size (bug #59063).
Markus Meisinger <chloros2@gmx.de>
parents:
29039
diff
changeset
|
796 || (val(i) < 0 && oldval(i) >= 0)))) // decreasing |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
797 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
798 index.resize (index.numel () + 1); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
799 index (index.numel () - 1) = i; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
800 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
801 } |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
802 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
803 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
|
804 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
805 temp = 1; // register only the first event |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
806 te.resize (1); |
27182 | 807 ye.resize (1, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
808 ie.resize (1); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
809 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
810 // Linear interpolation |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
811 ie(0) = index(0); |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
812 te(0) = tsol - val (index(0)) * (tsol - told) |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27929
diff
changeset
|
813 / (val (index(0)) - oldval (index(0))); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
814 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
815 ColumnVector ytemp |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
816 = 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
|
817 |
27182 | 818 for (octave_idx_type i = 0; i < m_num; i++) |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
819 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
|
820 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
821 } |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
822 else if (index.numel () > 0) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
823 // 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
|
824 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
825 te.resize (temp + index.numel ()); |
27182 | 826 ye.resize (temp + index.numel (), m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
827 ie.resize (temp + index.numel ()); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
828 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
829 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
|
830 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
831 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
832 if (isterminal (index(i)) == 1) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
833 status = 1; // Stop integration |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
834 |
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
835 // Linear interpolation |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
836 ie(temp+i) = index(i); |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
837 te(temp+i) = tsol - val(index(i)) * (tsol - told) |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27929
diff
changeset
|
838 / (val(index(i)) - oldval(index(i))); |
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 ColumnVector ytemp |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
841 = 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
|
842 |
27182 | 843 for (octave_idx_type j = 0; j < m_num; j++) |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
844 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
|
845 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
846 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
847 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
848 temp += index.numel (); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
849 } |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
850 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
851 // Update variables |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
852 yold = y; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
853 told = tsol; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
854 olddir = dir; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
855 oldval = val; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
856 oldisterminal = isterminal; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
857 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
858 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
859 return status; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
860 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
861 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
862 bool |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
863 IDA::interpolate (octave_idx_type& cont, Matrix& output, ColumnVector& tout, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
864 int refine, realtype tend, bool haveoutputfcn, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
865 bool haveoutputsel, const octave_value& output_fcn, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
866 ColumnVector& outputsel, bool haveeventfunction, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
867 const octave_value& event_fcn, ColumnVector& te, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
868 Matrix& ye, ColumnVector& ie, ColumnVector& oldval, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
869 ColumnVector& oldisterminal, ColumnVector& olddir, |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
870 octave_idx_type& temp, ColumnVector& yold) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
871 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
872 realtype h = 0, tcur = 0; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
873 bool status = 0; |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
874 |
27182 | 875 N_Vector dky = N_VNew_Serial (m_num); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
876 |
27182 | 877 N_Vector dkyp = N_VNew_Serial (m_num); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
878 |
27182 | 879 ColumnVector yout (m_num); |
880 ColumnVector ypout (m_num); | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
881 std::string string = ""; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
882 |
27182 | 883 if (IDAGetLastStep (m_mem, &h) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
884 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
|
885 |
27182 | 886 if (IDAGetCurrentTime (m_mem, &tcur) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
887 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
|
888 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
889 realtype tin = tcur - h; |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
890 |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
891 realtype step = h / refine; |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
892 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
893 for (octave_idx_type i = 1; |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
894 i < refine && tin + step * i < tend && status == 0; |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
895 i++) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
896 { |
27182 | 897 if (IDAGetDky (m_mem, tin + step*i, 0, dky) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
898 error ("IDA failed to interpolate y"); |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
899 |
27182 | 900 if (IDAGetDky (m_mem, tin + step*i, 1, dkyp) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
901 error ("IDA failed to interpolate yp"); |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
902 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
903 cont += 1; |
27182 | 904 output.resize (cont + 1, m_num); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
905 tout.resize (cont + 1); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
906 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
907 tout(cont) = tin + step * i; |
27182 | 908 yout = NVecToCol (dky, m_num); |
909 ypout = NVecToCol (dkyp, m_num); | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
910 |
27182 | 911 for (octave_idx_type j = 0; j < m_num; j++) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
912 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
|
913 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
914 if (haveoutputfcn) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
915 status = IDA::outputfun (output_fcn, haveoutputsel, yout, |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
916 tout(cont), tend, outputsel, ""); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
917 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
918 if (haveeventfunction) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
919 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
|
920 yout, string, ypout, oldval, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
921 oldisterminal, olddir, cont, temp, |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
922 tout(cont-1), yold); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
923 } |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
924 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
925 N_VDestroy_Serial (dky); |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
926 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
927 return status; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
928 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
929 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
930 bool |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
931 IDA::outputfun (const octave_value& output_fcn, bool haveoutputsel, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
932 const ColumnVector& yout, realtype tsol, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
933 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
|
934 const std::string& flag) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
935 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
936 bool status = 0; |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
937 |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
938 octave_value_list output; |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
939 output(2) = flag; |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
940 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
941 ColumnVector ysel (outputsel.numel ()); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
942 if (haveoutputsel) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
943 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
944 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
|
945 ysel(i) = yout(outputsel(i)); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
946 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
947 output(1) = ysel; |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
948 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
949 else |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
950 output(1) = yout; |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
951 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
952 if (flag == "init") |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
953 { |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
954 ColumnVector toutput (2); |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
955 toutput(0) = tsol; |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
956 toutput(1) = tend; |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
957 output(0) = toutput; |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
958 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23588
diff
changeset
|
959 feval (output_fcn, output, 0); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
960 } |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
961 else if (flag == "") |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
962 { |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
963 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
|
964 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
|
965 status = val(0).bool_value (); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
966 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
967 else |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25098
diff
changeset
|
968 { |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25098
diff
changeset
|
969 // Cleanup plotter |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
970 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
|
971 feval (output_fcn, output, 0); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
972 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
973 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
974 return status; |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
975 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
976 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
977 void |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
978 IDA::set_maxstep (realtype maxstep) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
979 { |
27182 | 980 if (IDASetMaxStep (m_mem, maxstep) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
981 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
|
982 } |
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 void |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
985 IDA::set_initialstep (realtype initialstep) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
986 { |
27182 | 987 if (IDASetInitStep (m_mem, initialstep) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
988 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
|
989 } |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
990 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
991 void |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
992 IDA::set_maxorder (int maxorder) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
993 { |
27182 | 994 if (IDASetMaxOrd (m_mem, maxorder) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
995 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
|
996 } |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
997 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
998 void |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
999 IDA::print_stat (void) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1000 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1001 long int nsteps = 0, netfails = 0, nrevals = 0; |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1002 |
27182 | 1003 if (IDAGetNumSteps (m_mem, &nsteps) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1004 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
|
1005 |
27182 | 1006 if (IDAGetNumErrTestFails (m_mem, &netfails) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1007 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
|
1008 |
27182 | 1009 if (IDAGetNumResEvals (m_mem, &nrevals) != 0) |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1010 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
|
1011 |
26000
97e63ba8a34c
* __ode15__.cc (IDA::print_stat): Use octave_stdout instead of std::cout.
John W. Eaton <jwe@octave.org>
parents:
25438
diff
changeset
|
1012 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
|
1013 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
|
1014 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
|
1015 // 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
|
1016 // 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
|
1017 // octave_stdout << " solutions of linear systems\n"; |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1018 } |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1019 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1020 ColumnVector |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1021 ida_user_function (const ColumnVector& x, const ColumnVector& xdot, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
1022 double t, const octave_value& ida_fc) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1023 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1024 octave_value_list tmp; |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1025 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1026 try |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1027 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23588
diff
changeset
|
1028 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
|
1029 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29060
diff
changeset
|
1030 catch (execution_exception& ee) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1031 { |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29060
diff
changeset
|
1032 err_user_supplied_eval (ee, "__ode15__"); |
22901
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 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1035 return tmp(0).vector_value (); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1036 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1037 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1038 Matrix |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1039 ida_dense_jac (const ColumnVector& x, const ColumnVector& xdot, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
1040 double t, double cj, const octave_value& ida_jc) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1041 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1042 octave_value_list tmp; |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1043 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1044 try |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1045 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23588
diff
changeset
|
1046 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
|
1047 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29060
diff
changeset
|
1048 catch (execution_exception& ee) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1049 { |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29060
diff
changeset
|
1050 err_user_supplied_eval (ee, "__ode15__"); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1051 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1052 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1053 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
|
1054 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1055 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1056 SparseMatrix |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1057 ida_sparse_jac (const ColumnVector& x, const ColumnVector& xdot, |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
1058 double t, double cj, const octave_value& ida_jc) |
22901
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 octave_value_list tmp; |
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 try |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1063 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23588
diff
changeset
|
1064 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
|
1065 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29060
diff
changeset
|
1066 catch (execution_exception& ee) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1067 { |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29060
diff
changeset
|
1068 err_user_supplied_eval (ee, "__ode15__"); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1069 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1070 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1071 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
|
1072 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1073 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1074 Matrix |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1075 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
|
1076 { |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1077 return (*dfdy) + cj * (*dfdyp); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1078 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1079 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1080 SparseMatrix |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1081 ida_sparse_cell_jac (SparseMatrix *spdfdy, SparseMatrix *spdfdyp, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1082 double cj) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1083 { |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1084 return (*spdfdy) + cj * (*spdfdyp); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1085 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1086 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1087 octave_value_list |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
1088 do_ode15 (const octave_value& ida_fcn, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1089 const ColumnVector& tspan, |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
1090 const octave_idx_type numt, |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1091 const realtype t0, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1092 const ColumnVector& y0, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1093 const ColumnVector& yp0, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1094 const octave_scalar_map& options) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1095 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1096 octave_value_list retval; |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1097 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1098 // Create object |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1099 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
|
1100 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1101 // Set Jacobian |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1102 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
|
1103 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1104 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
|
1105 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1106 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
|
1107 |
27182 | 1108 Matrix ida_dfdy, ida_dfdyp; |
1109 SparseMatrix ida_spdfdy, ida_spdfdyp; | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1110 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1111 if (havejac) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1112 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1113 if (havejacfun) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1114 { |
27182 | 1115 octave_value ida_jac = options.getfield ("Jacobian"); |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1116 |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1117 if (havejacsparse) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1118 dae.set_jacobian (ida_jac, ida_sparse_jac); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1119 else |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1120 dae.set_jacobian (ida_jac, ida_dense_jac); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1121 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1122 else |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1123 { |
27182 | 1124 Cell jaccell = options.getfield ("Jacobian").cell_value (); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1125 |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1126 if (havejacsparse) |
22901
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 ida_spdfdy = jaccell(0).sparse_matrix_value (); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1129 ida_spdfdyp = jaccell(1).sparse_matrix_value (); |
27182 | 1130 |
1131 dae.set_jacobian (&ida_spdfdy, &ida_spdfdyp, | |
1132 ida_sparse_cell_jac); | |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1133 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1134 else |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1135 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1136 ida_dfdy = jaccell(0).matrix_value (); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1137 ida_dfdyp = jaccell(1).matrix_value (); |
27182 | 1138 |
1139 dae.set_jacobian (&ida_dfdy, &ida_dfdyp, ida_dense_cell_jac); | |
22901
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 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1142 } |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1143 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1144 // Initialize IDA |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1145 dae.initialize (); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1146 |
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1147 // Set tolerances |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1148 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
|
1149 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1150 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
|
1151 |
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1152 if (haveabstolvec) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1153 { |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1154 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
|
1155 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1156 dae.set_tolerance (abs_tol, rel_tol); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1157 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1158 else |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1159 { |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1160 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
|
1161 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1162 dae.set_tolerance (abs_tol, rel_tol); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1163 } |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1164 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1165 //Set max step |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1166 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
|
1167 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1168 dae.set_maxstep (maxstep); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1169 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1170 //Set initial step |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1171 if (! options.getfield ("InitialStep").isempty ()) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1172 { |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1173 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
|
1174 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1175 dae.set_initialstep (initialstep); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1176 } |
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 //Set max order FIXME: it doesn't work |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1179 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
|
1180 |
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1181 dae.set_maxorder (maxorder); |
22901
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 //Set Refine |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1184 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
|
1185 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1186 bool haverefine = (refine > 1); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1187 |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
1188 octave_value output_fcn; |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1189 ColumnVector outputsel; |
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 // OutputFcn |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1192 bool haveoutputfunction |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1193 = options.getfield ("haveoutputfunction").bool_value (); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1194 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1195 if (haveoutputfunction) |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1196 output_fcn = options.getfield ("OutputFcn"); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1197 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1198 // OutputSel |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1199 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
|
1200 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1201 if (haveoutputsel) |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1202 outputsel = options.getfield ("OutputSel").vector_value (); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1203 |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
1204 octave_value event_fcn; |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1205 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1206 // Events |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1207 bool haveeventfunction |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1208 = options.getfield ("haveeventfunction").bool_value (); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1209 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1210 if (haveeventfunction) |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1211 event_fcn = options.getfield ("Events"); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1212 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1213 // 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
|
1214 dae.set_up (y0); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1215 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1216 // Integrate |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1217 retval = dae.integrate (numt, tspan, y0, yp0, refine, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1218 haverefine, haveoutputfunction, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1219 output_fcn, haveoutputsel, outputsel, |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1220 haveeventfunction, event_fcn); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1221 |
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1222 // Statistics |
28694
d91935bd879c
maint: Use Octave coding conventions in __ode15__.cc.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1223 bool havestats = options.getfield ("havestats").bool_value (); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1224 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1225 if (havestats) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1226 dae.print_stat (); |
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 return retval; |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1229 } |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1230 } |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1231 #endif |
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 |
22913
69342e4f0dcf
* __ode15__.cc: Don't check nargout.
John W. Eaton <jwe@octave.org>
parents:
22912
diff
changeset
|
1234 DEFUN_DLD (__ode15__, args, , |
69342e4f0dcf
* __ode15__.cc: Don't check nargout.
John W. Eaton <jwe@octave.org>
parents:
22912
diff
changeset
|
1235 doc: /* -*- texinfo -*- |
23565
3a730821e4a2
doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents:
23480
diff
changeset
|
1236 @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
|
1237 Undocumented internal function. |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1238 @end deftypefn */) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1239 { |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1240 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1241 #if defined (HAVE_SUNDIALS) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1242 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1243 // Check number of parameters |
28952
351f6eb2aba5
maint: Don't declare nargin in C++ files if it is used only once.
Rik <rik@octave.org>
parents:
28857
diff
changeset
|
1244 if (args.length () != 5) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1245 print_usage (); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1246 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1247 // Check odefun |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
1248 octave_value ida_fcn = args(0); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1249 |
26907
1d3730539776
use octave_value instead of pointer to octave_function in __ode15__
John W. Eaton <jwe@octave.org>
parents:
26905
diff
changeset
|
1250 if (! ida_fcn.is_function_handle ()) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1251 error ("__ode15__: odefun must be a function handle"); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1252 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1253 // Check input tspan |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1254 ColumnVector tspan |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1255 = 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
|
1256 |
28716
9beec32ba3d6
Overhaul usage of integer types in __ode15__.cc (bug #58795).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28709
diff
changeset
|
1257 octave_idx_type numt = tspan.numel (); |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1258 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1259 realtype t0 = tspan (0); |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1260 |
22910
23847979b91e
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22903
diff
changeset
|
1261 if (numt < 2) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1262 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
|
1263 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
|
1264 error ("__ode15__: TRANGE must be strictly monotonic"); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1265 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1266 // input y0 and yp0 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1267 ColumnVector y0 |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1268 = 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
|
1269 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1270 ColumnVector yp0 |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1271 = 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
|
1272 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1273 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1274 if (y0.numel () != yp0.numel ()) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1275 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
|
1276 else if (y0.numel () < 1) |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1277 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
|
1278 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1279 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1280 if (! args(4).isstruct ()) |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1281 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
|
1282 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1283 octave_scalar_map options |
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1284 = 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
|
1285 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1286 |
22917
c1ac4ac3ebbc
* __ode15__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
22915
diff
changeset
|
1287 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
|
1288 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1289 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1290 #else |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1291 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1292 octave_unused_parameter (args); |
22911
82551783527f
* __ode15__.cc: Fix compilation if Sundials is missing.
John W. Eaton <jwe@octave.org>
parents:
22910
diff
changeset
|
1293 |
22901
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1294 err_disabled_feature ("__ode15__", "sundials_ida, sundials_nvecserial"); |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1295 |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1296 #endif |
4c56f3ffec04
Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff
changeset
|
1297 } |
26905
91e5d37aaba0
__ode15__.cc: mark internal function as tested for BIST purposes
Mike Miller <mtmiller@octave.org>
parents:
26903
diff
changeset
|
1298 |
91e5d37aaba0
__ode15__.cc: mark internal function as tested for BIST purposes
Mike Miller <mtmiller@octave.org>
parents:
26903
diff
changeset
|
1299 /* |
91e5d37aaba0
__ode15__.cc: mark internal function as tested for BIST purposes
Mike Miller <mtmiller@octave.org>
parents:
26903
diff
changeset
|
1300 ## No test needed for internal helper function. |
91e5d37aaba0
__ode15__.cc: mark internal function as tested for BIST purposes
Mike Miller <mtmiller@octave.org>
parents:
26903
diff
changeset
|
1301 %!assert (1) |
91e5d37aaba0
__ode15__.cc: mark internal function as tested for BIST purposes
Mike Miller <mtmiller@octave.org>
parents:
26903
diff
changeset
|
1302 */ |