Skip to content

Commit

Permalink
Merge pull request #622 from oscardssmith/os/prepare-DAESolution-for-…
Browse files Browse the repository at this point in the history
…interpolation

Prepare `DAESolution` for interpolation
  • Loading branch information
ChrisRackauckas authored Feb 13, 2024
2 parents 7611e76 + a2627da commit 0475fc3
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/solutions/dae_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ https://docs.sciml.ai/DiffEqDocs/stable/basics/solution/
exited due to an error. For more details, see
[the return code documentation](https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/#retcodes).
"""
struct DAESolution{T, N, uType, duType, uType2, DType, tType, P, A, ID, S} <:
struct DAESolution{T, N, uType, duType, uType2, DType, tType, P, A, ID, S, rateType} <:
AbstractDAESolution{T, N, uType}
u::uType
du::duType
u_analytic::uType2
errors::DType
t::tType
k::rateType
prob::P
alg::A
interp::ID
Expand Down Expand Up @@ -84,17 +85,18 @@ function build_solution(prob::AbstractDAEProblem, alg, t, u, du = nothing;
end
Base.depwarn(msg, :build_solution)
end

if has_analytic(prob.f)
u_analytic = Vector{typeof(prob.u0)}()
errors = Dict{Symbol, real(eltype(prob.u0))}()

sol = DAESolution{T, N, typeof(u), typeof(du), typeof(u_analytic), typeof(errors),
typeof(t),
typeof(prob), typeof(alg), typeof(interp), typeof(stats)}(u, du,
typeof(t), typeof(prob), typeof(alg), typeof(interp), typeof(stats), typeof(k)}(
u,
du,
u_analytic,
errors,
t,
k,
prob,
alg,
interp,
Expand All @@ -110,9 +112,10 @@ function build_solution(prob::AbstractDAEProblem, alg, t, u, du = nothing;
sol
else
DAESolution{T, N, typeof(u), typeof(du), Nothing, Nothing, typeof(t),
typeof(prob), typeof(alg), typeof(interp), typeof(stats)}(u, du,
typeof(prob), typeof(alg), typeof(interp), typeof(stats), typeof(k)}(
u, du,
nothing,
nothing, t,
nothing, t, k,
prob, alg,
interp,
dense, 0,
Expand Down Expand Up @@ -161,12 +164,13 @@ end

function build_solution(sol::AbstractDAESolution{T, N}, u_analytic, errors) where {T, N}
DAESolution{T, N, typeof(sol.u), typeof(sol.du), typeof(u_analytic), typeof(errors),
typeof(sol.t),
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.stats)}(sol.u,
typeof(sol.t), typeof(sol.prob), typeof(sol.alg), typeof(sol.interp),
typeof(sol.stats), typeof(sol.k)}(sol.u,
sol.du,
u_analytic,
errors,
sol.t,
sol.k,
sol.prob,
sol.alg,
sol.interp,
Expand All @@ -178,12 +182,13 @@ end

function solution_new_retcode(sol::AbstractDAESolution{T, N}, retcode) where {T, N}
DAESolution{T, N, typeof(sol.u), typeof(sol.du), typeof(sol.u_analytic),
typeof(sol.errors), typeof(sol.t),
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.stats)}(sol.u,
typeof(sol.errors), typeof(sol.t), typeof(sol.prob), typeof(sol.alg),
typeof(sol.interp), typeof(sol.stats), typeof(sol.k)}(sol.u,
sol.du,
sol.u_analytic,
sol.errors,
sol.t,
sol.k,
sol.prob,
sol.alg,
sol.interp,
Expand All @@ -195,12 +200,13 @@ end

function solution_new_tslocation(sol::AbstractDAESolution{T, N}, tslocation) where {T, N}
DAESolution{T, N, typeof(sol.u), typeof(sol.du), typeof(sol.u_analytic),
typeof(sol.errors), typeof(sol.t),
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.stats)}(sol.u,
typeof(sol.errors), typeof(sol.t), typeof(sol.prob), typeof(sol.alg),
typeof(sol.interp), typeof(sol.stats), typeof(k)}(sol.u,
sol.du,
sol.u_analytic,
sol.errors,
sol.t,
sol.k,
sol.prob,
sol.alg,
sol.interp,
Expand All @@ -212,15 +218,16 @@ end

function solution_slice(sol::AbstractDAESolution{T, N}, I) where {T, N}
DAESolution{T, N, typeof(sol.u), typeof(sol.du), typeof(sol.u_analytic),
typeof(sol.errors), typeof(sol.t),
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.stats)}(sol.u[I],
typeof(sol.errors), typeof(sol.t), typeof(sol.prob), typeof(sol.alg),
typeof(sol.interp), typeof(sol.stats), typeof(sol.k)}(sol.u[I],
sol.du[I],
sol.u_analytic ===
nothing ?
nothing :
sol.u_analytic[I],
sol.errors,
sol.t[I],
sol.k[I],
sol.prob,
sol.alg,
sol.interp,
Expand Down

0 comments on commit 0475fc3

Please sign in to comment.