I have some background with Modelica, where the specification and modification of defaults is relatively simple. From the ModelingToolkit
documentation [p. 2 of ModelingToolkit.jl
documentation]:
Often it is a good idea to specify reasonable values for the initial state and the parameters of a model component. Then, these do not have to be explicitly specified when constructing the
ODEProblem
.function unitstep_fol_factory(;name) @parameters τ @variables t x(t) ODESystem(D(x) ~ (1 - x)/τ; name, defaults=Dict(x=>0.0, τ=>1.0)) end ODEProblem(unitstep_fol_factory(name=:fol),[],(0.0,5.0),[]) |> solve
If I don’t specify defaults, initial values and parameters are specified by (separate) arrays of pairs, e.g., [x => 0]
, [tau => 1.0]
. But for defaults, it seems like the default initial values and parameters are specified in a single dictionary.
OK – not a big problem [although somewhat unsystematic?]
Question 1: if I specify defaults, do I need to specify defaults for all states and parameters, or is it possible to specify defaults for a subset? [And… if the system is not in state space form but needs to be “reduced” to state space form by index reduction, etc. – how can I know how many states there are? Normally, I’d have to do structural_simplify
first to see the names of the states??]
Question 2: how do I specify parameters that differ from default values? I don’t want to specify all parameters, but just those that are different.
- Do I simply add parameters or initial values that differ from the defaults?
- Or do I need to specify the complete set of values? [Which would reduce the advantage of specifying defaults.]
In other words, if the defaults are as follows (assume different system, but same name as example above…):
..., defaults = Dict(x => 0, y => 1.0, a => 3.0, b => 2.0))
and I want to change initial value of y
and parameter value of a
(but keep the defaults of x
and b
), I do:
u0 = [y => -1.0]
p = [a => 2.5]
ODEProblem(unitstep_fol_factory(name=:fol),u0,(0.0,5.0),p) |> solve
Or is there another way to do it?