2
2
TestSolution
3
3
4
4
"""
5
- type TestSolution{hasinterp} <: DESolution
6
- t
7
- u
8
- interp
9
- dense
5
+ type TestSolution{T,N, hasinterp,tType,uType,iType } <: AbstractTimeseriesSolution{T,N}
6
+ t:: tType
7
+ u:: uType
8
+ interp:: iType
9
+ dense:: Bool
10
10
end
11
11
(T:: TestSolution )(t) = T. interp (t)
12
- TestSolution (t,u) = TestSolution {false} (t,u,nothing ,false )
13
- TestSolution (t,u,interp) = TestSolution {true} (t,u,interp,true )
14
- TestSolution (interp:: DESolution ) = TestSolution {true} (nothing ,nothing ,interp,true )
12
+ function TestSolution (t,u)
13
+ T = eltype (eltype (u))
14
+ N = length ((size (u[1 ])... , length (u)))
15
+ TestSolution {T,N,false,typeof(t),typeof(u),Void} (t,u,nothing ,false )
16
+ end
17
+ function TestSolution (t,u,interp)
18
+ T = eltype (eltype (u))
19
+ N = length ((size (u[1 ])... , length (u)))
20
+ TestSolution {T,N,length(true),typeof(t),typeof(u),typeof(interp)} (t,u,interp,true )
21
+ end
22
+ TestSolution (interp:: DESolution ) = TestSolution {Void,0,true,Void,Void,typeof(interp)} (nothing ,nothing ,interp,true )
15
23
16
24
"""
17
25
`appxtrue(sol::AbstractODESolution,sol2::TestSolution)`
@@ -25,17 +33,17 @@ function appxtrue{hasinterp}(sol::AbstractODESolution,sol2::TestSolution{hasinte
25
33
sol2. u = sol2 (sol. t)
26
34
sol2. t = sol. t
27
35
end
28
- errors = Dict (:final => mean (abs .(sol[end ]- sol2[end ])))
36
+ errors = Dict (:final => recursive_mean (abs .(sol[end ]- sol2[end ])))
29
37
if sol2. dense
30
38
timeseries_analytic = sol2 (sol. t)
31
39
errors[:l∞ ] = maximum (vecvecapply ((x)-> abs .(x),sol[:]- timeseries_analytic))
32
- errors[:l2 ] = sqrt (mean (vecvecapply ((x)-> float (x).^ 2 ,sol[:]- timeseries_analytic)))
40
+ errors[:l2 ] = sqrt (recursive_mean (vecvecapply ((x)-> float (x).^ 2 ,sol[:]- timeseries_analytic)))
33
41
if ! (typeof (sol) <: AbstractRODESolution ) && sol. dense
34
42
densetimes = collect (linspace (sol. t[1 ],sol. t[end ],100 ))
35
43
interp_u = sol (densetimes)
36
44
interp_analytic = sol2 (densetimes)
37
45
interp_errors = Dict (:L∞ => maximum (vecvecapply ((x)-> abs .(x),interp_u- interp_analytic)),
38
- :L2 => sqrt (mean (vecvecapply ((x)-> float (x).^ 2 ,interp_u- interp_analytic))))
46
+ :L2 => sqrt (recursive_mean (vecvecapply ((x)-> float (x).^ 2 ,interp_u- interp_analytic))))
39
47
errors = merge (errors,interp_errors)
40
48
end
41
49
end
@@ -56,15 +64,15 @@ errors for sol. If sol2 has no interpolant, only the final error is
56
64
calculated.
57
65
"""
58
66
function appxtrue (sol:: AbstractODESolution ,sol2:: AbstractODESolution )
59
- errors = Dict (:final => mean (abs .(sol[end ]- sol2[end ])))
67
+ errors = Dict (:final => recursive_mean (abs .(sol[end ]- sol2[end ])))
60
68
if ! (typeof (sol2) <: AbstractRODESolution ) && sol2. dense
61
69
timeseries_analytic = sol2 (sol. t)
62
- errors = Dict (:final => mean (abs .(sol[end ]- sol2[end ])),:l∞ => maximum (vecvecapply ((x)-> abs .(x),sol[:]- timeseries_analytic)),:l2 => sqrt (mean (vecvecapply ((x)-> float (x).^ 2 ,sol[:]- timeseries_analytic))))
70
+ errors = Dict (:final => recursive_mean (abs .(sol[end ]- sol2[end ])),:l∞ => maximum (vecvecapply ((x)-> abs .(x),sol[:]- timeseries_analytic)),:l2 => sqrt (recursive_mean (vecvecapply ((x)-> float (x).^ 2 ,sol[:]- timeseries_analytic))))
63
71
if ! (typeof (sol) <: AbstractRODESolution ) && sol. dense
64
72
densetimes = collect (linspace (sol. t[1 ],sol. t[end ],100 ))
65
73
interp_u = sol (densetimes)
66
74
interp_analytic = sol2 (densetimes)
67
- interp_errors = Dict (:L∞ => maximum (vecvecapply ((x)-> abs .(x),interp_u- interp_analytic)),:L2 => sqrt (mean (vecvecapply ((x)-> float (x).^ 2 ,interp_u- interp_analytic))))
75
+ interp_errors = Dict (:L∞ => maximum (vecvecapply ((x)-> abs .(x),interp_u- interp_analytic)),:L2 => sqrt (recursive_mean (vecvecapply ((x)-> float (x).^ 2 ,interp_u- interp_analytic))))
68
76
errors = merge (errors,interp_errors)
69
77
end
70
78
end
0 commit comments