|
17 | 17 | function TestSolution(t,u,interp)
|
18 | 18 | T = eltype(eltype(u))
|
19 | 19 | N = length((size(u[1])..., length(u)))
|
20 |
| - TestSolution{T,N,length(true),typeof(t),typeof(u),typeof(interp)}(t,u,interp,true) |
| 20 | + TestSolution{T,N,true,typeof(t),typeof(u),typeof(interp)}(t,u,interp,true) |
21 | 21 | end
|
22 | 22 | TestSolution(interp::DESolution) = TestSolution{Void,0,true,Void,Void,typeof(interp)}(nothing,nothing,interp,true)
|
23 |
| - |
| 23 | +hasinterp{T,N,hi,tType,uType,iType}(::TestSolution{T,N,hi,tType,uType,iType}) = hi |
24 | 24 | """
|
25 | 25 | `appxtrue(sol::AbstractODESolution,sol2::TestSolution)`
|
26 | 26 |
|
27 | 27 | Uses the interpolant from the higher order solution sol2 to approximate
|
28 | 28 | errors for sol. If sol2 has no interpolant, only the final error is
|
29 | 29 | calculated.
|
30 | 30 | """
|
31 |
| -function appxtrue{hasinterp}(sol::AbstractODESolution,sol2::TestSolution{hasinterp}) |
32 |
| - if sol2.u == nothing && hasinterp |
33 |
| - sol2.u = sol2(sol.t) |
34 |
| - sol2.t = sol.t |
| 31 | +function appxtrue(sol::AbstractODESolution,sol2::TestSolution) |
| 32 | + if sol2.u == nothing && hasinterp(sol2) |
| 33 | + _sol = TestSolution(sol.t,sol2(sol.t),sol2) |
| 34 | + else |
| 35 | + _sol = sol2 |
35 | 36 | end
|
36 |
| - errors = Dict(:final=>recursive_mean(abs.(sol[end]-sol2[end]))) |
37 |
| - if sol2.dense |
38 |
| - timeseries_analytic = sol2(sol.t) |
| 37 | + |
| 38 | + errors = Dict(:final=>recursive_mean(abs.(sol[end]-_sol[end]))) |
| 39 | + if _sol.dense |
| 40 | + timeseries_analytic = _sol(sol.t) |
39 | 41 | errors[:l∞] = maximum(vecvecapply((x)->abs.(x),sol[:]-timeseries_analytic))
|
40 | 42 | errors[:l2] = sqrt(recursive_mean(vecvecapply((x)->float(x).^2,sol[:]-timeseries_analytic)))
|
41 | 43 | if !(typeof(sol) <: AbstractRODESolution) && sol.dense
|
42 | 44 | densetimes = collect(linspace(sol.t[1],sol.t[end],100))
|
43 | 45 | interp_u = sol(densetimes)
|
44 |
| - interp_analytic = sol2(densetimes) |
| 46 | + interp_analytic = _sol(densetimes) |
45 | 47 | interp_errors = Dict(:L∞=>maximum(vecvecapply((x)->abs.(x),interp_u-interp_analytic)),
|
46 | 48 | :L2=>sqrt(recursive_mean(vecvecapply((x)->float(x).^2,interp_u-interp_analytic))))
|
47 | 49 | errors = merge(errors,interp_errors)
|
48 | 50 | end
|
49 | 51 | end
|
50 |
| - build_solution(sol,sol2.u,errors) |
| 52 | + build_solution(sol,_sol.u,errors) |
51 | 53 | end
|
52 | 54 |
|
53 | 55 | function appxtrue(sol::AbstractFEMSolution,sol2::AbstractFEMSolution)
|
|
0 commit comments