Skip to content

Commit 7f77f95

Browse files
Return all eocs in convergence_test (#285)
* return all eocs in convergence_test * adjust tests * add NEWS entry * Update src/util.jl Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com> --------- Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
1 parent 8b89f24 commit 7f77f95

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ DispersiveShallowWater.jl follows the interpretation of
55
used in the Julia ecosystem. Notable changes will be documented in this file
66
for human readability.
77

8+
## Changes when updating to v0.10 from v0.9.x
9+
10+
#### Changed
11+
12+
- `convergence_test` now returns the complete convergence orders. To obtain the mean convergence rates, use `DispersiveShallowWater.calc_mean_convergence` on the convergence orders ([#285]).
13+
814
## Changes when updating to v0.9 from v0.8.x
915

1016
#### Changed

src/util.jl

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ function analyze_convergence(io, errors, iterations, semi::Semidiscretization, N
124124
return analyze_convergence(io, errors, iterations, variablenames, Ns)
125125
end
126126

127+
"""
128+
DispersiveShallowWater.calc_mean_convergence(eocs)
129+
130+
Calculate the mean convergence rates from the given experimental orders of convergence `eocs`.
131+
The `eocs` are expected to be in the format returned by [`convergence_test`](@ref), i.e., a `Dict` where
132+
the keys are the error types (e.g., `:l2`, `:linf`) and the values are matrices with the EOCs for each
133+
variable in the columns and the iterations in the rows.
134+
Returns a `Dict` with the same keys as `eocs` and the mean convergence rates for all variables as values.
135+
"""
136+
function calc_mean_convergence(eocs)
137+
return Dict(kind => [sum(eocs[kind][:, v]) / length(eocs[kind][:, v])
138+
for v in 1:size(eocs[kind], 2)]
139+
for kind in keys(eocs))
140+
end
141+
127142
# This method is called with the collected error values to actually compute and print the EOC
128143
function analyze_convergence(io, errors, iterations,
129144
variablenames::Union{Tuple, AbstractArray}, Ns)
@@ -139,8 +154,7 @@ function analyze_convergence(io, errors, iterations,
139154
log.(Ns[1:(end - 1)] ./ Ns[2:end])
140155
for (kind, error) in errorsmatrix)
141156

142-
eoc_mean_values = Dict{Symbol, Any}()
143-
eoc_mean_values[:variables] = variablenames
157+
eoc_mean_values = calc_mean_convergence(eocs)
144158

145159
for (kind, error) in errorsmatrix
146160
println(io, kind)
@@ -177,18 +191,15 @@ function analyze_convergence(io, errors, iterations,
177191
println(io, "")
178192

179193
# Print mean EOCs
180-
mean_values = zeros(nvariables)
181194
for v in 1:nvariables
182-
mean_values[v] = sum(eocs[kind][:, v]) ./ length(eocs[kind][:, v])
183195
@printf(io, "%-15s", "mean")
184-
@printf(io, "%-10.2f", mean_values[v])
196+
@printf(io, "%-10.2f", eoc_mean_values[kind][v])
185197
end
186-
eoc_mean_values[kind] = mean_values
187198
println(io, "")
188199
println(io, "-"^100)
189200
end
190201

191-
return eoc_mean_values, errorsmatrix
202+
return eocs, errorsmatrix
192203
end
193204

194205
function extract_initial_N(example, kwargs)

test/test_unit.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,19 +540,21 @@ end
540540

541541
accuracy_orders = [2, 4, 6]
542542
for accuracy_order in accuracy_orders
543-
eoc_mean_values, _ = convergence_test(@__MODULE__, default_example(), 2, N = 256,
544-
tspan = (0.0, 1.0),
545-
accuracy_order = accuracy_order)
543+
eocs, _ = convergence_test(@__MODULE__, default_example(), 2, N = 256,
544+
tspan = (0.0, 1.0),
545+
accuracy_order = accuracy_order)
546+
eoc_mean_values = DispersiveShallowWater.calc_mean_convergence(eocs)
546547
@test isapprox(eoc_mean_values[:l2][1], accuracy_order, atol = 0.5)
547548
@test isapprox(eoc_mean_values[:linf][1], accuracy_order, atol = 0.5)
548549
@test isapprox(eoc_mean_values[:l2][2], accuracy_order, atol = 0.5)
549550
@test isapprox(eoc_mean_values[:linf][2], accuracy_order, atol = 0.5)
550551

551-
eoc_mean_values2, _ = convergence_test(@__MODULE__, default_example(), [256, 512],
552-
tspan = (0.0, 1.0),
553-
accuracy_order = accuracy_order)
552+
eocs2, _ = convergence_test(@__MODULE__, default_example(), [256, 512],
553+
tspan = (0.0, 1.0),
554+
accuracy_order = accuracy_order)
555+
eoc_mean_values2 = DispersiveShallowWater.calc_mean_convergence(eocs2)
554556
for kind in (:l2, :linf), variable in (1, 2)
555-
eoc_mean_values[kind][variable] == eoc_mean_values2[kind][variable]
557+
@test eoc_mean_values[kind][variable] == eoc_mean_values2[kind][variable]
556558
end
557559
end
558560
end

0 commit comments

Comments
 (0)