annotate libinterp/dldfcn/__ode15__.cc @ 28694:d91935bd879c

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