1
- struct NewtonRaphson{CS, AD, FDT, L, P, ST, CJ} <: AbstractNewtonAlgorithm{CS, AD, FDT, ST, CJ}
1
+ struct NewtonRaphson{CS, AD, FDT, L, P, ST, CJ} < :
2
+ AbstractNewtonAlgorithm{CS, AD, FDT, ST, CJ}
2
3
linsolve:: L
3
4
precs:: P
4
5
end
5
6
6
7
function NewtonRaphson (; chunk_size = Val {0} (), autodiff = Val {true} (),
7
- standardtag = Val {true} (), concrete_jac = nothing ,
8
- diff_type = Val{:forward }, linsolve = nothing , precs = DEFAULT_PRECS)
8
+ standardtag = Val {true} (), concrete_jac = nothing ,
9
+ diff_type = Val{:forward }, linsolve = nothing , precs = DEFAULT_PRECS)
9
10
NewtonRaphson{_unwrap_val (chunk_size), _unwrap_val (autodiff), diff_type,
10
- typeof (linsolve), typeof (precs), _unwrap_val (standardtag),
11
- _unwrap_val (concrete_jac)}(linsolve, precs)
11
+ typeof (linsolve), typeof (precs), _unwrap_val (standardtag),
12
+ _unwrap_val (concrete_jac)}(linsolve, precs)
12
13
end
13
14
14
15
mutable struct NewtonRaphsonCache{ufType, L, jType, uType, JC}
22
23
function dolinsolve (precs:: P , linsolve; A = nothing , linu = nothing , b = nothing ,
23
24
du = nothing , u = nothing , p = nothing , t = nothing ,
24
25
weight = nothing , solverdata = nothing ,
25
- reltol = nothing ) where P
26
+ reltol = nothing ) where {P}
26
27
A != = nothing && (linsolve = LinearSolve. set_A (linsolve, A))
27
28
b != = nothing && (linsolve = LinearSolve. set_b (linsolve, b))
28
29
linu != = nothing && (linsolve = LinearSolve. set_u (linsolve, linu))
@@ -33,7 +34,7 @@ function dolinsolve(precs::P, linsolve; A = nothing, linu = nothing, b = nothing
33
34
linsolve. Pr
34
35
35
36
_Pl, _Pr = precs (linsolve. A, du, u, p, nothing , A != = nothing , Plprev, Prprev,
36
- solverdata)
37
+ solverdata)
37
38
if (_Pl != = nothing || _Pr != = nothing )
38
39
_weight = weight === nothing ?
39
40
(linsolve. Pr isa Diagonal ? linsolve. Pr. diag : linsolve. Pr. inner. diag) :
@@ -68,7 +69,7 @@ function wrapprecs(_Pl, _Pr, weight)
68
69
end
69
70
70
71
function alg_cache (alg:: NewtonRaphson , f, u, p, :: Val{true} )
71
- uf = JacobianWrapper (f,p)
72
+ uf = JacobianWrapper (f, p)
72
73
J = false .* u .* u'
73
74
74
75
linprob = LinearProblem (W, _vec (zero (u)); u0 = _vec (zero (u)))
@@ -103,12 +104,12 @@ function perform_step(solver::NewtonImmutableSolver, alg::NewtonRaphson, ::Val{t
103
104
@unpack J, linsolve, du1 = cache
104
105
calc_J! (J, solver, cache)
105
106
# u = u - J \ fu
106
- linsolve = dolinsolve (alg. precs, solver. linsolve, A = J, b = fu, u = du1,
107
+ linsolve = dolinsolve (alg. precs, solver. linsolve, A = J, b = fu, u = du1,
107
108
p = p, reltol = solver. tol)
108
- @set! cache. linsolve = linsolve
109
+ @set! cache. linsolve = linsolve
109
110
@. u = u - du1
110
111
f (fu, u, p)
111
-
112
+
112
113
if solver. internalnorm (solver. fu) < solver. tol
113
114
@set! solver. force_stop = true
114
115
end
0 commit comments