-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add SummaryCallback * format * bump compat of TimerOutputs to v0.5.23 * fix test printing SummaryCallback * put timer inside function
- Loading branch information
1 parent
cc91146
commit 9c5db6a
Showing
9 changed files
with
82 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
end | ||
|
||
include("save_solution.jl") | ||
include("summary.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
SummaryCallback(io::IO = stdout) | ||
Create and return a callback that resets the timer at the beginning of | ||
a simulation and prints the timer values at the end of the simulation. | ||
""" | ||
struct SummaryCallback | ||
io::IO | ||
|
||
function SummaryCallback(io::IO = stdout) | ||
summary_callback = new(io) | ||
# SummaryCallback is never called during the simulation | ||
condition = (u, t, integrator) -> false | ||
DiscreteCallback(condition, summary_callback, | ||
save_positions = (false, false), | ||
initialize = initialize_summary_callback, | ||
finalize = finalize_summary_callback) | ||
end | ||
end | ||
|
||
function Base.show(io::IO, cb::DiscreteCallback{<:Any, <:SummaryCallback}) | ||
@nospecialize cb # reduce precompilation time | ||
|
||
print(io, "SummaryCallback") | ||
end | ||
|
||
function initialize_summary_callback(cb::DiscreteCallback, u, t, integrator) | ||
reset_timer!(timer()) | ||
return nothing | ||
end | ||
|
||
# the summary callback does nothing when called accidentally | ||
(cb::SummaryCallback)(integrator) = u_modified!(integrator, false) | ||
|
||
# At the end of the simulation, the timer is printed | ||
function finalize_summary_callback(cb::DiscreteCallback, u, t, integrator) | ||
io = cb.affect!.io | ||
TimerOutputs.complement!(timer()) | ||
print_timer(io, timer(), title = "KernelInterpolation", | ||
allocations = true, linechars = :unicode, compact = false) | ||
println(io) | ||
return nothing | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters