Skip to content

Commit 2d2e443

Browse files
committed
expose what was already there; that you can alter different p contaienrs
1 parent b270b00 commit 2d2e443

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicalSystemsBase"
22
uuid = "6e36e845-645a-534a-86f2-f5d4aa5a06b4"
33
repo = "https://github.com/JuliaDynamics/DynamicalSystemsBase.jl.git"
4-
version = "3.5.3"
4+
version = "3.5.4"
55

66
[deps]
77
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

src/core/dynamicalsystem_interface.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,12 @@ See also [`initial_parameters`](@ref), [`current_parameter`](@ref), [`set_parame
216216
current_parameters(ds::DynamicalSystem) = ds.p
217217

218218
"""
219-
current_parameter(ds::DynamicalSystem, index)
219+
current_parameter(ds::DynamicalSystem, index [,p])
220220
221-
Return the specific parameter corresponding to `index`,
221+
Return the specific parameter of `ds` corresponding to `index`,
222222
which can be anything given to [`set_parameter!`](@ref).
223+
`p` defaults to [`current_parameters`](@ref) and is the parameter container
224+
to extract the parameter from, which must match layout with its default value.
223225
"""
224226
function current_parameter(ds::DynamicalSystem, index, p = current_parameters(ds))
225227
prob = referrenced_sciml_prob(ds)
@@ -351,7 +353,7 @@ function set_state!(u::AbstractArray, value::Real, i, ds::DynamicalSystem)
351353
end
352354

353355
"""
354-
set_parameter!(ds::DynamicalSystem, index, value)
356+
set_parameter!(ds::DynamicalSystem, index, value [, p])
355357
356358
Change a parameter of `ds` given the `index` it has in the parameter container
357359
and the `value` to set it to. This function works for any type of parameter container
@@ -361,6 +363,10 @@ The `index` can be a traditional Julia index (integer for arrays, key for dictio
361363
or symbol for composite types). It can also be a symbolic variable.
362364
This is valid only for dynamical systems referring a ModelingToolkit.jl model
363365
which also has `index` as one of its parameters.
366+
367+
The last optional argument `p` defaults to [`current_parameters`](@ref) and is
368+
the parameter container whose value is changed at the given index.
369+
It must match layout with its default value.
364370
"""
365371
function set_parameter!(ds::DynamicalSystem, index, value, p = current_parameters(ds))
366372
# internal function is necessary so that we are able to call `u_modified!` for ODEs.

test/mtk_integration.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ set_parameter!(ds, fol_1.τ, 2.0)
4949
@test current_parameter(ds, 1) == 2.0
5050
@test current_parameter(ds, fol_1.τ) == 2.0
5151

52+
# pure parameter container
53+
pp = deepcopy(current_parameters(ds))
54+
set_parameter!(ds, fol_1.τ, 4.0)
55+
@test current_parameter(ds, fol_1.τ, pp) == 4.0
56+
5257
# states and observed variables
5358
@test observe_state(ds, 1) == -0.5
5459
@test observe_state(ds, fol_1.x) == -0.5

0 commit comments

Comments
 (0)