|
| 1 | +""" |
| 2 | + parameter_values(p) |
| 3 | +
|
| 4 | +Return an indexable collection containing the value of each parameter in `p`. |
| 5 | +""" |
| 6 | +function parameter_values end |
| 7 | + |
| 8 | +""" |
| 9 | + getp(sys, p) |
| 10 | +
|
| 11 | +Return a function that takes an integrator or solution of `sys`, and returns the value of |
| 12 | +the parameter `p`. Requires that the integrator or solution implement |
| 13 | +[`parameter_values`](@ref). |
| 14 | +""" |
| 15 | +function getp(sys, p) |
| 16 | + symtype = symbolic_type(p) |
| 17 | + elsymtype = symbolic_type(eltype(p)) |
| 18 | + if symtype != NotSymbolic() |
| 19 | + return _getp(sys, symtype, p) |
| 20 | + else |
| 21 | + return _getp(sys, elsymtype, p) |
| 22 | + end |
| 23 | +end |
| 24 | + |
| 25 | +function _getp(sys, ::NotSymbolic, p) |
| 26 | + return function getter(sol) |
| 27 | + return parameter_values(sol)[p] |
| 28 | + end |
| 29 | +end |
| 30 | + |
| 31 | +function _getp(sys, ::ScalarSymbolic, p) |
| 32 | + idx = parameter_index(sys, p) |
| 33 | + return function getter(sol) |
| 34 | + return parameter_values(sol)[idx] |
| 35 | + end |
| 36 | +end |
| 37 | + |
| 38 | +function _getp(sys, ::ScalarSymbolic, p::Union{Tuple,AbstractArray}) |
| 39 | + idxs = parameter_index.((sys,), p) |
| 40 | + return function getter(sol) |
| 41 | + return getindex.((parameter_values(sol),), idxs) |
| 42 | + end |
| 43 | +end |
| 44 | + |
| 45 | +function _getp(sys, ::ArraySymbolic, p) |
| 46 | + return getp(sys, collect(p)) |
| 47 | +end |
| 48 | + |
| 49 | +""" |
| 50 | + setp(sys, p) |
| 51 | +
|
| 52 | +Return a function that takes an integrator of `sys` and a value, and sets the |
| 53 | +the parameter `p` to that value. Requires that the integrator implement |
| 54 | +[`parameter_values`](@ref) and the returned collection be a mutable reference |
| 55 | +to the parameter vector in the integrator. |
| 56 | +""" |
| 57 | +function setp(sys, p) |
| 58 | + symtype = symbolic_type(p) |
| 59 | + elsymtype = symbolic_type(eltype(p)) |
| 60 | + if symtype != NotSymbolic() |
| 61 | + return _setp(sys, symtype, p) |
| 62 | + else |
| 63 | + return _setp(sys, elsymtype, p) |
| 64 | + end |
| 65 | +end |
| 66 | + |
| 67 | +function _setp(sys, ::NotSymbolic, p) |
| 68 | + return function setter!(sol, val) |
| 69 | + parameter_values(sol)[p] = val |
| 70 | + end |
| 71 | +end |
| 72 | + |
| 73 | +function _setp(sys, ::ScalarSymbolic, p) |
| 74 | + idx = parameter_index(sys, p) |
| 75 | + return function setter!(sol, val) |
| 76 | + parameter_values(sol)[idx] = val |
| 77 | + end |
| 78 | +end |
| 79 | + |
| 80 | +function _setp(sys, ::ScalarSymbolic, p::Union{Tuple,AbstractArray}) |
| 81 | + idxs = parameter_index.((sys,), p) |
| 82 | + return function setter!(sol, val) |
| 83 | + setindex!.((parameter_values(sol),), val, idxs) |
| 84 | + end |
| 85 | +end |
| 86 | + |
| 87 | +function _setp(sys, ::ArraySymbolic, p) |
| 88 | + return setp(sys, collect(p)) |
| 89 | +end |
0 commit comments