From b8c86b671784fb1604c472133e58c2d87b528760 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Thu, 11 Aug 2022 08:04:23 +0200 Subject: [PATCH 1/3] allow other RHS in analysis callback --- src/callbacks_step/analysis.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index 65fd417c691..498fc65ea4d 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -219,7 +219,7 @@ 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) + @notimeit timer() integrator.f(du_ode, integrator.u, semi, t) 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) From b53bd814e598e0b24804d70940633babca27d0b5 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Thu, 11 Aug 2022 08:54:23 +0200 Subject: [PATCH 2/3] adapt simple integrators --- src/time_integration/methods_2N.jl | 7 ++++--- src/time_integration/methods_3Sstar.jl | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/time_integration/methods_2N.jl b/src/time_integration/methods_2N.jl index 5af93613a08..47a83fddf2a 100644 --- a/src/time_integration/methods_2N.jl +++ b/src/time_integration/methods_2N.jl @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/time_integration/methods_3Sstar.jl b/src/time_integration/methods_3Sstar.jl index e3317bd8000..416d6dca9c9 100644 --- a/src/time_integration/methods_3Sstar.jl +++ b/src/time_integration/methods_3Sstar.jl @@ -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 @@ -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 @@ -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 From 02a1c220af919ef704bbd2c89fbb1bf563b5c37e Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Thu, 11 Aug 2022 10:41:05 +0200 Subject: [PATCH 3/3] comment on ODE RHS call Co-authored-by: Michael Schlottke-Lakemper --- src/callbacks_step/analysis.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/callbacks_step/analysis.jl b/src/callbacks_step/analysis.jl index 498fc65ea4d..59b2d2e9113 100644 --- a/src/callbacks_step/analysis.jl +++ b/src/callbacks_step/analysis.jl @@ -219,6 +219,10 @@ function (analysis_callback::AnalysisCallback)(integrator) # Calculate current time derivative (needed for semidiscrete entropy time derivative, residual, etc.) du_ode = first(get_tmp_cache(integrator)) + # `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) u = wrap_array(integrator.u, mesh, equations, solver, cache) du = wrap_array(du_ode, mesh, equations, solver, cache)