Skip to content

Commit

Permalink
Add original and resid to ODEsolution (used for BVPs)
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Dec 21, 2023
1 parent 5ceb8cc commit 05ca0fc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/problems/bvp_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ struct FakeSolutionObject{U}
end

(sol::FakeSolutionObject)(t) = sol.u
Base.length(::FakeSolutionObject) = 1
Base.firstindex(::FakeSolutionObject) = 1
Base.lastindex(::FakeSolutionObject) = 1
Base.getindex(sol::FakeSolutionObject, i::Int) = sol.u

TruncatedStacktraces.@truncate_stacktrace BVProblem 3 1 2
Expand Down
41 changes: 29 additions & 12 deletions src/solutions/ode_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ https://docs.sciml.ai/DiffEqDocs/stable/basics/solution/
[the return code documentation](https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/#retcodes).
"""
struct ODESolution{T, N, uType, uType2, DType, tType, rateType, P, A, IType, S,
AC <: Union{Nothing, Vector{Int}}} <:
AC <: Union{Nothing, Vector{Int}}, R, O} <:
AbstractODESolution{T, N, uType}
u::uType
u_analytic::uType2
Expand All @@ -115,6 +115,8 @@ struct ODESolution{T, N, uType, uType2, DType, tType, rateType, P, A, IType, S,
stats::S
alg_choice::AC
retcode::ReturnCode.T
resid::R
original::O
end

Base.@propagate_inbounds function Base.getproperty(x::AbstractODESolution, s::Symbol)
Expand All @@ -125,13 +127,15 @@ Base.@propagate_inbounds function Base.getproperty(x::AbstractODESolution, s::Sy
return getfield(x, s)
end

# FIXME: Remove the defaults for resid and original on a breaking release
function ODESolution{T, N}(u, u_analytic, errors, t, k, prob, alg, interp, dense,
tslocation, stats, alg_choice, retcode) where {T, N}
tslocation, stats, alg_choice, retcode, resid = nothing,
original = nothing) where {T, N}
return ODESolution{T, N, typeof(u), typeof(u_analytic), typeof(errors), typeof(t),
typeof(k), typeof(prob), typeof(alg), typeof(interp),
typeof(stats),
typeof(alg_choice)}(u, u_analytic, errors, t, k, prob, alg, interp,
dense, tslocation, stats, alg_choice, retcode)
typeof(stats), typeof(alg_choice), typeof(resid),
typeof(original)}(u, u_analytic, errors, t, k, prob, alg, interp,
dense, tslocation, stats, alg_choice, retcode, resid, original)
end

function (sol::AbstractODESolution)(t, ::Type{deriv} = Val{0}; idxs = nothing,
Expand Down Expand Up @@ -213,6 +217,7 @@ function build_solution(prob::Union{AbstractODEProblem, AbstractDDEProblem},
alg_choice = nothing,
interp = LinearInterpolation(t, u),
retcode = ReturnCode.Default, destats = missing, stats = nothing,
resid = nothing, original = nothing,
kwargs...)
T = eltype(eltype(u))

Expand Down Expand Up @@ -252,7 +257,9 @@ function build_solution(prob::Union{AbstractODEProblem, AbstractDDEProblem},
0,
stats,
alg_choice,
retcode)
retcode,
resid,
original)
if calculate_error
calculate_solution_errors!(sol; timeseries_errors = timeseries_errors,
dense_errors = dense_errors)
Expand All @@ -270,7 +277,9 @@ function build_solution(prob::Union{AbstractODEProblem, AbstractDDEProblem},
0,
stats,
alg_choice,
retcode)
retcode,
resid,
original)
end
end

Expand Down Expand Up @@ -326,7 +335,9 @@ function build_solution(sol::ODESolution{T, N}, u_analytic, errors) where {T, N}
sol.tslocation,
sol.stats,
sol.alg_choice,
sol.retcode)
sol.retcode,
sol.resid,
sol.original)
end

function solution_new_retcode(sol::ODESolution{T, N}, retcode) where {T, N}
Expand All @@ -342,7 +353,9 @@ function solution_new_retcode(sol::ODESolution{T, N}, retcode) where {T, N}
sol.tslocation,
sol.stats,
sol.alg_choice,
retcode)
retcode,
sol.resid,
sol.original)
end

function solution_new_tslocation(sol::ODESolution{T, N}, tslocation) where {T, N}
Expand All @@ -358,7 +371,9 @@ function solution_new_tslocation(sol::ODESolution{T, N}, tslocation) where {T, N
tslocation,
sol.stats,
sol.alg_choice,
sol.retcode)
sol.retcode,
sol.resid,
sol.original)
end

function solution_slice(sol::ODESolution{T, N}, I) where {T, N}
Expand All @@ -374,7 +389,9 @@ function solution_slice(sol::ODESolution{T, N}, I) where {T, N}
sol.tslocation,
sol.stats,
sol.alg_choice,
sol.retcode)
sol.retcode,
sol.resid,
sol.original)
end

function sensitivity_solution(sol::ODESolution, u, t)
Expand All @@ -392,5 +409,5 @@ function sensitivity_solution(sol::ODESolution, u, t)
nothing, sol.prob,
sol.alg, interp,
sol.dense, sol.tslocation,
sol.stats, sol.alg_choice, sol.retcode)
sol.stats, sol.alg_choice, sol.retcode, sol.resid, sol.original)
end

0 comments on commit 05ca0fc

Please sign in to comment.