public API
(
switch to internal
)
-
revision 3.6.7
casadi
core
runtime
casadi_newton.hpp
1
//
2
// MIT No Attribution
3
//
4
// Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl, KU Leuven.
5
//
6
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
7
// software and associated documentation files (the "Software"), to deal in the Software
8
// without restriction, including without limitation the rights to use, copy, modify,
9
// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
10
// permit persons to whom the Software is furnished to do so.
11
//
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
15
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
16
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
17
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
//
19
20
// SYMBOL "newton_mem"
21
22
template
<
typename
T1>
23
struct
casadi_newton_mem
{
24
casadi_int
n
;
25
T1
abstol
;
26
T1
abstol_step
;
27
T1*
x
;
28
T1*
g
;
29
T1*
jac_g_x
;
30
31
const
casadi_int*
sp_a
;
32
const
casadi_int*
sp_v
;
33
const
casadi_int*
sp_r
;
34
const
casadi_int*
prinv
;
35
const
casadi_int*
pc
;
36
37
T1*
lin_w
;
38
T1*
lin_v
;
39
T1*
lin_r
;
40
T1*
lin_beta
;
41
};
42
43
// C-REPLACE "casadi_newton_mem<T1>" "struct casadi_newton_mem"
44
// SYMBOL "newton"
45
template
<
typename
T1>
46
int
casadi_newton(
const
casadi_newton_mem<T1>
* m) {
47
// Check tolerance on residual
48
if
(m->
abstol
>0 && casadi_norm_inf(m->
n
, m->
g
) <= m->
abstol
)
return
1;
49
50
// Factorize J
51
casadi_qr(m->
sp_a
, m->
jac_g_x
, m->
lin_w
,
52
m->
sp_v
, m->
lin_v
, m->
sp_r
, m->
lin_r
, m->
lin_beta
,
53
m->
prinv
, m->
pc
);
54
// Solve J^(-1) g
55
casadi_qr_solve(m->
g
, 1, 0, m->
sp_v
, m->
lin_v
, m->
sp_r
, m->
lin_r
, m->
lin_beta
,
56
m->
prinv
, m->
pc
, m->
lin_w
);
57
58
// Update Xk+1 = Xk - J^(-1) g
59
casadi_axpy(m->
n
, -1., m->
g
, m->
x
);
60
61
// Check tolerance on step
62
if
(m->
abstol_step
>0 && casadi_norm_inf(m->
n
, m->
g
) <= m->
abstol_step
)
return
2;
63
64
// We will need another newton step
65
return
0;
66
}
casadi_newton_mem
Definition:
casadi_newton.hpp:23
casadi_newton_mem::lin_v
T1 * lin_v
Definition:
casadi_newton.hpp:38
casadi_newton_mem::g
T1 * g
Definition:
casadi_newton.hpp:28
casadi_newton_mem::abstol
T1 abstol
Definition:
casadi_newton.hpp:25
casadi_newton_mem::abstol_step
T1 abstol_step
Definition:
casadi_newton.hpp:26
casadi_newton_mem::sp_a
const casadi_int * sp_a
Definition:
casadi_newton.hpp:31
casadi_newton_mem::pc
const casadi_int * pc
Definition:
casadi_newton.hpp:35
casadi_newton_mem::sp_v
const casadi_int * sp_v
Definition:
casadi_newton.hpp:32
casadi_newton_mem::sp_r
const casadi_int * sp_r
Definition:
casadi_newton.hpp:33
casadi_newton_mem::jac_g_x
T1 * jac_g_x
Definition:
casadi_newton.hpp:29
casadi_newton_mem::x
T1 * x
Definition:
casadi_newton.hpp:27
casadi_newton_mem::lin_beta
T1 * lin_beta
Definition:
casadi_newton.hpp:40
casadi_newton_mem::prinv
const casadi_int * prinv
Definition:
casadi_newton.hpp:34
casadi_newton_mem::lin_w
T1 * lin_w
Definition:
casadi_newton.hpp:37
casadi_newton_mem::n
casadi_int n
Definition:
casadi_newton.hpp:24
casadi_newton_mem::lin_r
T1 * lin_r
Definition:
casadi_newton.hpp:39