Skip to content

Commit

Permalink
Add the opportunity to plot the errors of AnalysisCallback (#42)
Browse files Browse the repository at this point in the history
* add the opportunity to plot the errors of AnalysisCallback

* format
  • Loading branch information
JoshuaLampert authored Sep 24, 2023
1 parent 5396777 commit 547de79
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/callbacks_step/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ function (analysis_callback::AnalysisCallback)(u_ode, integrator, semi)
@unpack analysis_errors, analysis_integrals, tstops, errors, integrals = analysis_callback
@unpack t, dt = integrator
push!(tstops, t)
t_final = integrator.sol.prob.tspan[2]
iter = integrator.stats.naccept

# Compute the total runtime since the analysis callback has been initialized, in seconds
Expand All @@ -204,7 +205,7 @@ function (analysis_callback::AnalysisCallback)(u_ode, integrator, semi)
gc_time_absolute = 1.0e-9 * (Base.gc_time_ns() - analysis_callback.start_gc_time)

# Compute the percentage of total time that was spent in garbage collection
gc_time_percentage = gc_time_absolute / runtime_absolute * 10
gc_time_percentage = gc_time_absolute / runtime_absolute * 100

# Obtain the current memory usage of the Julia garbage collector, in MiB, i.e., the total size of
# objects in memory that have been allocated by the JIT compiler or the user code.
Expand All @@ -226,7 +227,7 @@ function (analysis_callback::AnalysisCallback)(u_ode, integrator, semi)
" " *
" └── GC time: " *
@sprintf("%10.8e s (%5.3f%%)", gc_time_absolute, gc_time_percentage))
println(" sim. time: " * @sprintf("%10.8e", t))
println(" sim. time: " * @sprintf("%10.8e (%5.3f%%)", t, t / t_final*100))
println(" #DOF: " * @sprintf("% 14d", nnodes(semi)) *
" " *
" alloc'd memory: " * @sprintf("%14.3f MiB", memory_use))
Expand Down
44 changes: 31 additions & 13 deletions src/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ end
end
end

# Plot the bathymetry if primitive variables are plotted
# Plot the bathymetry
if plot_bathymetry == true
@series begin
subplot := 1
linestyle := :solid
label := "bathymetry"
xguide := "x"
yguide := names[1]
Expand Down Expand Up @@ -172,19 +173,36 @@ end
PlotDataOverTime(semi => sol, x_value, conversion, yli)
end

# TODO: Only plot change in invariants for now, also plot errors?
@recipe function f(cb::DiscreteCallback{Condition, Affect!}) where {Condition,
Affect! <:
AnalysisCallback}
@recipe function f(cb::DiscreteCallback{Condition, Affect!}; what = (:integrals,),
label_extension = "") where {Condition, Affect! <: AnalysisCallback}
t = tstops(cb)
ints = integrals(cb)
plot_title --> "change of invariants"
for (name, integral) in pairs(ints)
@series begin
label := string(name)
xguide --> "t"
yguide --> "change of invariants"
t, integral .- integral[1]
subplot = 1
layout := length(what)
if :integrals in what
ints = integrals(cb)
plot_title --> "change of invariants"
for (name, integral) in pairs(ints)
@series begin
subplot := subplot
label := string(name) * " " * label_extension
xguide --> "t"
yguide --> "change of invariants"
t, integral .- integral[1]
end
end
subplot += 1
end
if :errors in what
errs = errors(cb)
plot_title --> "errors"
for (name, err) in pairs(errs)
@series begin
subplot := subplot
label := string(name) * " " * label_extension
xguide --> "t"
yguide --> "sum of errors"
t, dropdims(sum(err, dims = 1), dims = 1)
end
end
end
end

0 comments on commit 547de79

Please sign in to comment.