-
Notifications
You must be signed in to change notification settings - Fork 98
/
NonlinearSolvers.jl
75 lines (56 loc) · 1.57 KB
/
NonlinearSolvers.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
abstract type NonlinearSolver <: GridapType end
- [`solve!(x::AbstractVector,nls::NonlinearSolver,op::NonlinearOperator)`](@ref)
- [`solve!(x::AbstractVector,nls::NonlinearSolver,op::NonlinearOperator, cache)`](@ref)
"""
abstract type NonlinearSolver <: GridapType end
"""
solve!(x::AbstractVector,nls::NonlinearSolver,op::NonlinearOperator)
Usage:
cache = solve!(x,nls,op)
The returned `cache` object can be used in subsequent solves:
cache = solve!(x,nls,op,cache)
"""
function solve!(x::AbstractVector,nls::NonlinearSolver,op::NonlinearOperator)
solve!(x,nls,op,nothing)
end
"""
solve!(x::AbstractVector,nls::NonlinearSolver,op::NonlinearOperator,cache)
Solve using the cache object from a previous solve.
"""
function solve!(x::AbstractVector,nls::NonlinearSolver,op::NonlinearOperator,cache)
@abstractmethod
end
"""
solve(nls::NonlinearSolver,op::NonlinearOperator)
Creates and uses a zero initial guess.
"""
function solve(nls::NonlinearSolver,op::NonlinearOperator)
x = zero_initial_guess(op)
solve!(x,nls,op)
x
end
"""
test_nonlinear_solver(
nls::NonlinearSolver,
op::NonlinearOperator,
x0::AbstractVector,
x::AbstractVector,
pred::Function=isapprox)
"""
function test_nonlinear_solver(
nls::NonlinearSolver,
op::NonlinearOperator,
x0::AbstractVector,
x::AbstractVector,
pred::Function=isapprox)
x1 = copy(x0)
cache = solve!(x1,nls,op)
@test pred(x1,x)
x1 = copy(x0)
cache = solve!(x1,nls,op,cache)
@test pred(x1,x)
x1 = copy(x0)
cache = solve!(x1,nls,op,cache)
@test pred(x1,x)
end