Skip to content

Commit

Permalink
Add SummaryCallback (#75)
Browse files Browse the repository at this point in the history
* add SummaryCallback with TimerOutputs.jl

* format
  • Loading branch information
JoshuaLampert authored Dec 11, 2023
1 parent a52454f commit 20d957a
Show file tree
Hide file tree
Showing 29 changed files with 250 additions and 148 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SimpleUnPack = "ce78b400-467f-4804-87d8-8f486da07d0a"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
SummationByPartsOperators = "9f78cca6-572e-554e-b819-917d2f1cf240"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[compat]
DiffEqBase = "6.121"
Expand All @@ -32,4 +33,5 @@ SimpleUnPack = "1.1"
SparseArrays = "1"
StaticArrays = "1"
SummationByPartsOperators = "0.5.41"
TimerOutputs = "0.5"
julia = "1.8"
3 changes: 2 additions & 1 deletion examples/bbm_bbm_1d/bbm_bbm_1d_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 30.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
3 changes: 2 additions & 1 deletion examples/bbm_bbm_1d/bbm_bbm_1d_dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,

tspan = (0.0, 30.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
3 changes: 2 additions & 1 deletion examples/bbm_bbm_1d/bbm_bbm_1d_manufactured.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 1.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
3 changes: 2 additions & 1 deletion examples/bbm_bbm_1d/bbm_bbm_1d_relaxation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 30.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
relaxation_callback = RelaxationCallback(invariant = entropy)
# Always put relaxation_callback before analysis_callback to guarantee conservation of the invariant
callbacks = CallbackSet(relaxation_callback, analysis_callback)
callbacks = CallbackSet(relaxation_callback, analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 30.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 30.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
relaxation_callback = RelaxationCallback(invariant = entropy)
# Always put relaxation_callback before analysis_callback to guarantee conservation of the invariant
callbacks = CallbackSet(relaxation_callback, analysis_callback)
callbacks = CallbackSet(relaxation_callback, analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 70.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 500)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 1.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 30.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
relaxation_callback = RelaxationCallback(invariant = entropy)
# Always put relaxation_callback before analysis_callback to guarantee conservation of the invariant
callbacks = CallbackSet(relaxation_callback, analysis_callback)
callbacks = CallbackSet(relaxation_callback, analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 30.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
relaxation_callback = RelaxationCallback(invariant = entropy)
# Always put relaxation_callback before analysis_callback to guarantee conservation of the invariant
callbacks = CallbackSet(relaxation_callback, analysis_callback)
callbacks = CallbackSet(relaxation_callback, analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 30.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy,
lake_at_rest_error))
# Always put relaxation_callback before analysis_callback to guarantee conservation of the invariant
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

dt = 0.5
saveat = range(tspan..., length = 100)
Expand Down
3 changes: 2 additions & 1 deletion examples/svaerd_kalisch_1d/svaerd_kalisch_1d_dingemans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 70.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
entropy,
entropy_modified))
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 500)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
3 changes: 2 additions & 1 deletion examples/svaerd_kalisch_1d/svaerd_kalisch_1d_dingemans_cg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 70.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
entropy,
entropy_modified))
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 500)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 70.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
entropy,
entropy_modified))
relaxation_callback = RelaxationCallback(invariant = entropy_modified)
# Always put relaxation_callback before analysis_callback to guarantee conservation of the invariant
callbacks = CallbackSet(relaxation_callback, analysis_callback)
callbacks = CallbackSet(relaxation_callback, analysis_callback, summary_callback)

saveat = range(tspan..., length = 500)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 70.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
entropy,
entropy_modified))

callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 500)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
3 changes: 2 additions & 1 deletion examples/svaerd_kalisch_1d/svaerd_kalisch_1d_manufactured.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 1.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
velocity, entropy))
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

saveat = range(tspan..., length = 100)
sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ semi = Semidiscretization(mesh, equations, initial_condition, solver,
# Create `ODEProblem` and run the simulation
tspan = (0.0, 10.0)
ode = semidiscretize(semi, tspan)
summary_callback = SummaryCallback()
analysis_callback = AnalysisCallback(semi; interval = 10,
extra_analysis_errors = (:conservation_error,),
extra_analysis_integrals = (waterheight_total,
momentum, entropy,
lake_at_rest_error))
callbacks = CallbackSet(analysis_callback)
callbacks = CallbackSet(analysis_callback, summary_callback)

# Need a very small time step for stability
dt = 0.0002
Expand Down
3 changes: 2 additions & 1 deletion src/DispersiveShallowWater.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ using SummationByPartsOperators: AbstractDerivativeOperator,
periodic_derivative_operator,
derivative_order, integrate
import SummationByPartsOperators: grid, xmin, xmax
using TimerOutputs: TimerOutputs, TimerOutput, @timeit, print_timer, reset_timer!

include("boundary_conditions.jl")
include("mesh.jl")
Expand Down Expand Up @@ -52,7 +53,7 @@ export initial_condition_convergence_test,
initial_condition_manufactured, source_terms_manufactured,
initial_condition_dingemans

export AnalysisCallback, RelaxationCallback
export AnalysisCallback, RelaxationCallback, SummaryCallback
export tstops, errors, integrals

end
Loading

0 comments on commit 20d957a

Please sign in to comment.