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

Refactor time integrator 2N and 3Star more similar to OrdinaryDiffEq.jl integrators #1975

Merged
merged 11 commits into from
Jun 19, 2024
36 changes: 27 additions & 9 deletions src/time_integration/methods_2N.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ function Base.getproperty(integrator::SimpleIntegrator2N, field::Symbol)
return getfield(integrator, field)
end

# Fakes `solve`: https://diffeq.sciml.ai/v6.8/basics/overview/#Solving-the-Problems-1
function solve(ode::ODEProblem, alg::T;
dt, callback = nothing, kwargs...) where {T <: SimpleAlgorithm2N}
function init(ode::ODEProblem, alg::T;
dt, callback = nothing, kwargs...) where {T <: SimpleAlgorithm2N}
warisa-r marked this conversation as resolved.
Show resolved Hide resolved
u = copy(ode.u0)
du = similar(u)
u_tmp = similar(u)
Expand All @@ -129,10 +128,33 @@ function solve(ode::ODEProblem, alg::T;
error("unsupported")
end

solve!(integrator)
return integrator
end

# Fakes `solve`: https://diffeq.sciml.ai/v6.8/basics/overview/#Solving-the-Problems-1
function solve(ode::ODEProblem, alg::T;
dt, callback = nothing, kwargs...) where {T <: SimpleAlgorithm2N}
warisa-r marked this conversation as resolved.
Show resolved Hide resolved
integrator = init(ode, alg, dt = dt, callback = callback; kwargs...)

# Start actual solve
solve_steps!(integrator)
DanielDoehring marked this conversation as resolved.
Show resolved Hide resolved
end

function solve_steps!(integrator::SimpleIntegrator2N)
DanielDoehring marked this conversation as resolved.
Show resolved Hide resolved
@unpack prob = integrator.sol

integrator.finalstep = false

@trixi_timeit timer() "main loop" while !integrator.finalstep
step!(integrator)
end # "main loop" timer

return TimeIntegratorSolution((first(prob.tspan), integrator.t),
(prob.u0, integrator.u),
integrator.sol.prob)
end

function solve!(integrator::SimpleIntegrator2N)
function step!(integrator::SimpleIntegrator2N)
ranocha marked this conversation as resolved.
Show resolved Hide resolved
@unpack prob = integrator.sol
@unpack alg = integrator
t_end = last(prob.tspan)
Expand Down Expand Up @@ -186,10 +208,6 @@ function solve!(integrator::SimpleIntegrator2N)
terminate!(integrator)
end
end

return TimeIntegratorSolution((first(prob.tspan), integrator.t),
(prob.u0, integrator.u),
integrator.sol.prob)
end

# get a cache where the RHS can be stored
Expand Down
36 changes: 27 additions & 9 deletions src/time_integration/methods_3Sstar.jl
warisa-r marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ function Base.getproperty(integrator::SimpleIntegrator3Sstar, field::Symbol)
return getfield(integrator, field)
end

# Fakes `solve`: https://diffeq.sciml.ai/v6.8/basics/overview/#Solving-the-Problems-1
function solve(ode::ODEProblem, alg::T;
dt, callback = nothing, kwargs...) where {T <: SimpleAlgorithm3Sstar}
function init(ode::ODEProblem, alg::T;
dt, callback = nothing, kwargs...) where {T <: SimpleAlgorithm3Sstar}
warisa-r marked this conversation as resolved.
Show resolved Hide resolved
u = copy(ode.u0)
du = similar(u)
u_tmp1 = similar(u)
Expand All @@ -199,10 +198,33 @@ function solve(ode::ODEProblem, alg::T;
error("unsupported")
end

solve!(integrator)
return integrator
end

# Fakes `solve`: https://diffeq.sciml.ai/v6.8/basics/overview/#Solving-the-Problems-1
function solve(ode::ODEProblem, alg::T;
dt, callback = nothing, kwargs...) where {T <: SimpleAlgorithm3Sstar}
warisa-r marked this conversation as resolved.
Show resolved Hide resolved
integrator = init(ode, alg, dt = dt, callback = callback; kwargs...)

# Start actual solve
solve_steps!(integrator)
DanielDoehring marked this conversation as resolved.
Show resolved Hide resolved
end

function solve_steps!(integrator::SimpleIntegrator3Sstar)
DanielDoehring marked this conversation as resolved.
Show resolved Hide resolved
@unpack prob = integrator.sol

integrator.finalstep = false

@trixi_timeit timer() "main loop" while !integrator.finalstep
step!(integrator)
end # "main loop" timer

return TimeIntegratorSolution((first(prob.tspan), integrator.t),
(prob.u0, integrator.u),
integrator.sol.prob)
end

function solve!(integrator::SimpleIntegrator3Sstar)
function step!(integrator::SimpleIntegrator3Sstar)
@unpack prob = integrator.sol
@unpack alg = integrator
t_end = last(prob.tspan)
Expand Down Expand Up @@ -262,10 +284,6 @@ function solve!(integrator::SimpleIntegrator3Sstar)
terminate!(integrator)
end
end

return TimeIntegratorSolution((first(prob.tspan), integrator.t),
(prob.u0, integrator.u),
integrator.sol.prob)
end

# get a cache where the RHS can be stored
Expand Down
Loading