forked from SciML/SciMLBase.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem_interface.jl
75 lines (66 loc) · 3.09 KB
/
problem_interface.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Base.@propagate_inbounds function Base.getproperty(prob::AbstractSciMLProblem, sym::Symbol)
if sym === :ps
return ParameterIndexingProxy(prob)
end
return getfield(prob, sym)
end
SymbolicIndexingInterface.symbolic_container(prob::AbstractSciMLProblem) = prob.f
SymbolicIndexingInterface.symbolic_container(prob::AbstractJumpProblem) = prob.prob
SymbolicIndexingInterface.symbolic_container(prob::AbstractEnsembleProblem) = prob.prob
SymbolicIndexingInterface.parameter_values(prob::AbstractSciMLProblem) = prob.p
function SymbolicIndexingInterface.parameter_values(prob::AbstractJumpProblem)
parameter_values(prob.prob)
end
function SymbolicIndexingInterface.parameter_values(prob::AbstractEnsembleProblem)
parameter_values(prob.prob)
end
SymbolicIndexingInterface.state_values(prob::AbstractSciMLProblem) = prob.u0
SymbolicIndexingInterface.state_values(prob::AbstractJumpProblem) = state_values(prob.prob)
function SymbolicIndexingInterface.state_values(prob::AbstractEnsembleProblem)
state_values(prob.prob)
end
SymbolicIndexingInterface.current_time(prob::AbstractSciMLProblem) = prob.tspan[1]
SymbolicIndexingInterface.current_time(prob::AbstractJumpProblem) = current_time(prob.prob)
function SymbolicIndexingInterface.current_time(prob::AbstractEnsembleProblem)
current_time(prob.prob)
end
SymbolicIndexingInterface.current_time(::AbstractSteadyStateProblem) = Inf
Base.@propagate_inbounds function Base.getindex(
prob::AbstractSciMLProblem, ::SymbolicIndexingInterface.SolvedVariables)
return getindex(prob, variable_symbols(prob))
end
Base.@propagate_inbounds function Base.getindex(
prob::AbstractSciMLProblem, ::SymbolicIndexingInterface.AllVariables)
return getindex(prob, all_variable_symbols(prob))
end
Base.@propagate_inbounds function Base.getindex(A::AbstractSciMLProblem, sym)
if is_parameter(A, sym)
error("Indexing with parameters is deprecated. Use `prob.ps[$sym]` for parameter indexing.")
end
return getu(A, sym)(A)
end
Base.@propagate_inbounds function Base.getindex(
A::AbstractSciMLProblem, sym::Union{AbstractArray, Tuple})
if symbolic_type(sym) == NotSymbolic() && any(x -> is_parameter(A, x), sym) ||
is_parameter(A, sym)
error("Indexing with parameters is deprecated. Use `prob.ps[$sym]` for parameter indexing.")
end
return getu(A, sym)(A)
end
function Base.setindex!(prob::AbstractSciMLProblem, args...; kwargs...)
___internal_setindex!(prob::AbstractSciMLProblem, args...; kwargs...)
end
function ___internal_setindex!(A::AbstractSciMLProblem, val, sym)
if is_parameter(A, sym)
error("Indexing with parameters is deprecated. Use `prob.ps[$sym] = $val` for parameter indexing.")
end
return setu(A, sym)(A, val)
end
function ___internal_setindex!(
A::AbstractSciMLProblem, val, sym::Union{AbstractArray, Tuple})
if symbolic_type(sym) == NotSymbolic() && any(x -> is_parameter(A, x), sym) ||
is_parameter(A, sym)
error("Indexing with parameters is deprecated. Use `prob.ps[$sym] = $val` for parameter indexing.")
end
return setu(A, sym)(A, val)
end