Skip to content

Commit 702777d

Browse files
committed
test improvement
1 parent 7fdd379 commit 702777d

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/benchmark.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,6 @@ end
372372

373373
# Work precision information for a nonlinear problem.
374374
function WorkPrecision(prob::NonlinearProblem, alg, abstols, reltols, dts = nothing; name = nothing, appxsol = nothing, error_estimate = :l2, numruns = 20, seconds = 2, kwargs...)
375-
isnothing(appxsol) && error("Must provide the real value as the \"appxsol\" kwarg.")
376-
377375
N = length(abstols)
378376
errors = Vector{Float64}(undef, N)
379377
times = Vector{Float64}(undef, N)
@@ -397,7 +395,7 @@ function WorkPrecision(prob::NonlinearProblem, alg, abstols, reltols, dts = noth
397395
if isnothing(appxsol)
398396
errors[i] = sqrt(sum(abs2, sol.resid))
399397
else
400-
errors[i] = sqrt(sum(abs2, sol .- sol.resid))
398+
errors[i] = sqrt(sum(abs2, sol .- appxsol))
401399
end
402400
else
403401
error("Unsupported norm used: $(error_estimate).")
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
# Fetch pakages.
22
using NonlinearSolve, DiffEqDevTools, Plots
3+
using Test
34

45
# Prepares NonlinearProblem.
5-
let
6-
f(u, p) = u .- p
7-
u0 = [1.0, 1.0]
8-
p = 2.0
9-
static_prob = NonlinearProblem(f, u0, p)
10-
real_sol = solve(static_prob, NewtonRaphson(), reltol = 1e-15, abstol = 1e-15)
6+
f(u, p) = 3u .^3 .+ 2u .^2 .+ u + .- p
7+
u0 = [1.0, 6.0]
8+
p = [1.0, 3.0]
9+
static_prob = NonlinearProblem(f, u0, p)
10+
real_sol = solve(static_prob, NewtonRaphson(), reltol = 1e-15, abstol = 1e-15)
1111

12-
# Sets WP input.
13-
abstols = 1.0 ./ 10.0 .^ (8:12)
14-
reltols = 1.0 ./ 10.0 .^ (8:12)
15-
setups = [Dict(:alg=>NewtonRaphson())
16-
Dict(:alg=>TrustRegion())]
17-
solnames = ["NewtonRaphson";"TrustRegion"]
12+
# Sets WP input.
13+
abstols = 1.0 ./ 10.0 .^ (8:12)
14+
reltols = 1.0 ./ 10.0 .^ (8:12)
15+
setups = [Dict(:alg=>NewtonRaphson())
16+
Dict(:alg=>TrustRegion())]
17+
solnames = ["NewtonRaphson"; "TrustRegion"]
1818

19-
# Makes WP-diagram
20-
wp = WorkPrecisionSet(static_prob, abstols, reltols, setups; names=solnames, numruns=100, appxsol=real_sol, error_estimate=:l2)
19+
# Makes WP-diagram
20+
wp = WorkPrecisionSet(static_prob, abstols, reltols, setups; names=solnames, numruns=100, appxsol=real_sol, error_estimate=:l2)
2121

22-
# Checks that all errors are small (they definitely should be).
23-
@test all(vcat(getfield.(wp.wps, :errors)...) .< 10e-9)
22+
# Checks that all errors are small (they definitely should be).
23+
@test all(vcat(getfield.(wp.wps, :errors)...) .< 10e-9)
24+
@test length(plot(wp).series_list) == 2
2425

25-
# Check without appxsol.
26-
wp = WorkPrecisionSet(static_prob, abstols, reltols, setups; names=solnames, numruns=100, error_estimate=:l2)
27-
@test all(vcat(getfield.(wp.wps, :errors)...) .< 10e-9)
28-
end
26+
# Check without appxsol.
27+
wp = WorkPrecisionSet(static_prob, abstols, reltols, setups; names=solnames, numruns=100, error_estimate=:l2)
28+
@test all(vcat(getfield.(wp.wps, :errors)...) .< 10e-9)
29+
@test length(plot(wp).series_list) == 2

0 commit comments

Comments
 (0)