31
31
isnegative(sol::ODESolution)
32
32
33
33
Returns `true` if `sol.u` contains negative elements.
34
-
34
+
35
35
Please note that negative values may occur when plotting the solution, depending on the interpolation used.
36
36
37
37
See also [`isnonnegative`](@ref).
43
43
"""
44
44
isnonnegative(u)
45
45
46
- Negation of [`isnegative`](@ref).
46
+ Negation of [`isnegative`](@ref).
47
47
"""
48
48
isnonnegative (args... ) = ! isnegative (args... )
49
49
50
50
# ## Errors #########################################################################
51
51
"""
52
52
rel_max_error_tend(sol, ref_sol)
53
53
54
- Returns the relative maximum error between `sol` and `ref_sol` at time `sol.t[end]`.
54
+ Returns the relative maximum error between `sol` and `ref_sol` at time `sol.t[end]`.
55
55
"""
56
- function rel_max_error_tend (sol, ref_sol)
56
+ function rel_max_error_tend (sol:: AbstractVector , ref_sol:: AbstractVector )
57
57
return maximum (abs .((sol[end ] .- ref_sol[end ]) ./ ref_sol[end ]))
58
58
end
59
59
60
+ rel_max_error_tend (sol, ref_sol) = rel_max_error_tend (sol. u, ref_sol. u)
61
+
60
62
"""
61
63
rel_max_error_overall(sol, ref_sol)
62
64
63
- Returns the maximum of the relative maximum errors between `sol` and `ref_sol` over all time steps.
65
+ Returns the maximum of the relative maximum errors between `sol` and `ref_sol` over all time steps.
64
66
"""
65
- function rel_max_error_overall (sol, ref_sol)
67
+ function rel_max_error_overall (sol:: AbstractVector , ref_sol:: AbstractVector )
66
68
err = zero (eltype (eltype (sol)))
67
69
for i in eachindex (sol)
68
70
max_err_i = maximum (abs .((abs .(sol[i]) .- abs .(ref_sol[i])) ./ ref_sol[i]))
@@ -73,26 +75,32 @@ function rel_max_error_overall(sol, ref_sol)
73
75
return err
74
76
end
75
77
78
+ rel_max_error_overall (sol, ref_sol) = rel_max_error_overall (sol. u, ref_sol. u)
79
+
76
80
"""
77
81
rel_l1_error_tend(sol, ref_sol)
78
82
79
- Returns the relative l1 error between `sol` and `ref_sol` at time `sol.t[end]`.
83
+ Returns the relative l1 error between `sol` and `ref_sol` at time `sol.t[end]`.
80
84
"""
81
- function rel_l1_error_tend (sol, ref_sol)
85
+ function rel_l1_error_tend (sol:: AbstractVector , ref_sol:: AbstractVector )
82
86
return sum (abs .((sol[end ] .- ref_sol[end ]) ./ ref_sol[end ])) / length (ref_sol[end ])
83
87
end
84
88
89
+ rel_l1_error_tend (sol, ref_sol) = rel_l1_error_tend (sol. u, ref_sol. u)
90
+
85
91
"""
86
92
rel_l2_error_tend(sol, ref_sol)
87
93
88
- Returns the relative l2 error between `sol` and `ref_sol` at time `sol.t[end]`.
94
+ Returns the relative l2 error between `sol` and `ref_sol` at time `sol.t[end]`.
89
95
"""
90
- function rel_l2_error_tend (sol, ref_sol)
96
+ function rel_l2_error_tend (sol:: AbstractVector , ref_sol:: AbstractVector )
91
97
return sqrt (sum (abs2 .((sol[end ] .- ref_sol[end ]) ./ ref_sol[end ])) /
92
98
length (ref_sol[end ]))
93
99
end
94
100
95
- # ## Functions to compute work-precision diagrams ##########################################
101
+ rel_l2_error_tend (sol, ref_sol) = rel_l2_error_tend (sol. u, ref_sol. u)
102
+
103
+ # ## Functions to compute work-precision diagrams ##########################################
96
104
function _compute_time (benchmark_f, seconds, numruns)
97
105
benchmark_f () # pre-compile
98
106
127
135
128
136
"""
129
137
work_precision_fixed!(dict, prob, algs, labels, dts, alg_ref;
130
- compute_error = rel_max_error_tend,
138
+ compute_error = rel_max_error_tend,
131
139
seconds = 2,
132
140
numruns = 20)
133
141
)
@@ -170,14 +178,14 @@ end
170
178
"""
171
179
work_precision_fixed(prob, algs, labels, dts, alg_ref;
172
180
compute_error = rel_max_error_tend,
173
- seconds = 2,
181
+ seconds = 2,
174
182
numruns = 20)
175
183
176
- Returns a dictionary to create work-precision diagrams.
177
- The problem `prob` is solved by each algorithm in `algs` for all the step sizes defined in `dts`.
178
- For each step size the error and computing time are stored in the dictionary.
184
+ Returns a dictionary to create work-precision diagrams.
185
+ The problem `prob` is solved by each algorithm in `algs` for all the step sizes defined in `dts`.
186
+ For each step size the error and computing time are stored in the dictionary.
179
187
If the solve is not successful for a given step size, then `(Inf, Inf)` is stored in the dictionary.
180
- The strings in the array `labels` are used as keys of the dictionary.
188
+ The strings in the array `labels` are used as keys of the dictionary.
181
189
The reference solution used for error computations is computed with the algorithm `alg_ref`.
182
190
183
191
### Keyword arguments: ###
@@ -198,10 +206,10 @@ end
198
206
"""
199
207
work_precision_adaptive(prob, algs, labels, abstols, reltols, alg_ref;
200
208
adaptive_ref = false,
201
- abstol_ref = 1e-14,
209
+ abstol_ref = 1e-14,
202
210
reltol_ref = 1e-13,
203
211
compute_error = rel_max_error_tend,
204
- seconds = 2,
212
+ seconds = 2,
205
213
numruns = 20,
206
214
kwargs...)
207
215
@@ -251,18 +259,18 @@ end
251
259
"""
252
260
work_precision_adaptive(prob, algs, labels, abstols, reltols, alg_ref;
253
261
adaptive_ref = false,
254
- abstol_ref = 1e-14,
262
+ abstol_ref = 1e-14,
255
263
reltol_ref = 1e-13,
256
264
compute_error = rel_max_error_tend,
257
- seconds = 2,
258
- numruns = 20,
265
+ seconds = 2,
266
+ numruns = 20,
259
267
kwargs...)
260
268
261
- Returns a dictionary to create work-precision diagrams.
262
- The problem `prob` is solved by each algorithm in `algs` for all tolerances defined in `abstols` and `reltols`.
263
- For the respective tolerances the error and computing time are stored in the dictionary.
269
+ Returns a dictionary to create work-precision diagrams.
270
+ The problem `prob` is solved by each algorithm in `algs` for all tolerances defined in `abstols` and `reltols`.
271
+ For the respective tolerances the error and computing time are stored in the dictionary.
264
272
If the solve is not successful for the given tolerances, then `(Inf, Inf)` is stored in the dictionary.
265
- The strings in the array `labels` are used as keys of the dictionary.
273
+ The strings in the array `labels` are used as keys of the dictionary.
266
274
The reference solution used for error computations is computed with the algorithm `alg_ref`.
267
275
Additional keyword arguments are passed on to `solve`.
268
276
0 commit comments