Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow other RHS in analysis callback #1205

Merged
merged 3 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/callbacks_step/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ function (analysis_callback::AnalysisCallback)(integrator)

# Calculate current time derivative (needed for semidiscrete entropy time derivative, residual, etc.)
du_ode = first(get_tmp_cache(integrator))
@notimeit timer() rhs!(du_ode, integrator.u, semi, t)
# `integrator.f` is usually just a call to `rhs!`
# However, we want to allow users to modify the ODE RHS outside of Trixi.jl
# and allow us to pass a combined ODE RHS to OrdinaryDiffEq, e.g., for
# hyperbolic-parabolic systems.
@notimeit timer() integrator.f(du_ode, integrator.u, semi, t)
ranocha marked this conversation as resolved.
Show resolved Hide resolved
u = wrap_array(integrator.u, mesh, equations, solver, cache)
du = wrap_array(du_ode, mesh, equations, solver, cache)
l2_error, linf_error = analysis_callback(io, du, u, integrator.u, t, semi)
Expand Down
7 changes: 4 additions & 3 deletions src/time_integration/methods_2N.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end
# This implements the interface components described at
# https://diffeq.sciml.ai/v6.8/basics/integrator/#Handing-Integrators-1
# which are used in Trixi.
mutable struct SimpleIntegrator2N{RealT<:Real, uType, Params, Sol, Alg, SimpleIntegrator2NOptions}
mutable struct SimpleIntegrator2N{RealT<:Real, uType, Params, Sol, F, Alg, SimpleIntegrator2NOptions}
u::uType #
du::uType
u_tmp::uType
Expand All @@ -86,6 +86,7 @@ mutable struct SimpleIntegrator2N{RealT<:Real, uType, Params, Sol, Alg, SimpleIn
iter::Int # current number of time steps (iteration)
p::Params # will be the semidiscretization from Trixi
sol::Sol # faked
f::F
alg::Alg
opts::SimpleIntegrator2NOptions
finalstep::Bool # added for convenience
Expand All @@ -109,7 +110,7 @@ function solve(ode::ODEProblem, alg::T;
t = first(ode.tspan)
iter = 0
integrator = SimpleIntegrator2N(u, du, u_tmp, t, dt, zero(dt), iter, ode.p,
(prob=ode,), alg,
(prob=ode,), ode.f, alg,
SimpleIntegrator2NOptions(callback, ode.tspan; kwargs...), false)

# initialize callbacks
Expand Down Expand Up @@ -149,7 +150,7 @@ function solve!(integrator::SimpleIntegrator2N)
integrator.u_tmp .= 0
for stage in eachindex(alg.c)
t_stage = integrator.t + integrator.dt * alg.c[stage]
prob.f(integrator.du, integrator.u, prob.p, t_stage)
integrator.f(integrator.du, integrator.u, prob.p, t_stage)

a_stage = alg.a[stage]
b_stage_dt = alg.b[stage] * integrator.dt
Expand Down
5 changes: 3 additions & 2 deletions src/time_integration/methods_3Sstar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function SimpleIntegrator3SstarOptions(callback, tspan; maxiters=typemax(Int), k
callback, false, Inf, maxiters, [last(tspan)])
end

mutable struct SimpleIntegrator3Sstar{RealT<:Real, uType, Params, Sol, Alg, SimpleIntegrator3SstarOptions}
mutable struct SimpleIntegrator3Sstar{RealT<:Real, uType, Params, Sol, F, Alg, SimpleIntegrator3SstarOptions}
u::uType #
du::uType
u_tmp1::uType
Expand All @@ -116,6 +116,7 @@ mutable struct SimpleIntegrator3Sstar{RealT<:Real, uType, Params, Sol, Alg, Simp
iter::Int # current number of time step (iteration)
p::Params # will be the semidiscretization from Trixi
sol::Sol # faked
f::F
alg::Alg
opts::SimpleIntegrator3SstarOptions
finalstep::Bool # added for convenience
Expand All @@ -140,7 +141,7 @@ function solve(ode::ODEProblem, alg::T;
t = first(ode.tspan)
iter = 0
integrator = SimpleIntegrator3Sstar(u, du, u_tmp1, u_tmp2, t, dt, zero(dt), iter, ode.p,
(prob=ode,), alg,
(prob=ode,), ode.f, alg,
SimpleIntegrator3SstarOptions(callback, ode.tspan; kwargs...), false)

# initialize callbacks
Expand Down