Skip to content

Commit 4ca31a8

Browse files
implements process_p_u0_symbolic
1 parent 8203791 commit 4ca31a8

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/variables.jl

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,31 @@ end
111111
"""
112112
$(SIGNATURES)
113113
114-
Intercept the call to `handle_varmap` and convert it to an ordered list if the user has
115-
ModelingToolkit loaded, and the problem has a symbolic origin.
114+
Intercept the call to `process_p_u0_symbolic` and process symbolic maps of `p` and/or `u0` if the
115+
user has `ModelingToolkit` loaded.
116116
"""
117-
function SciMLBase.handle_varmap(varmap, sys::AbstractSystem; field = :states, kwargs...)
118-
out = varmap_to_vars(varmap, getfield(sys, field); kwargs...)
119-
return out
117+
function SciMLBase.process_p_u0_symbolic(prob::ODEProblem, p, u0)
118+
# check if a symbolic remake is possible
119+
if eltype(p) <: Pair
120+
hasproperty(prob.f, :sys) && hasfield(typeof(prob.f.sys), :ps) || throw(ArgumentError("This problem does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
121+
" Please use `remake` with the `p` keyword argument as a vector of values, paying attention to parameter order."))
122+
end
123+
if eltype(u0) <: Pair
124+
hasproperty(prob.f, :sys) && hasfield(typeof(prob.f.sys), :states) || throw(ArgumentError("This problem does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
125+
" Please use `remake` with the `u0` keyword argument as a vector of values, paying attention to state order."))
126+
end
127+
128+
# assemble defaults
129+
defs = defaults(prob.f.sys)
130+
defs = mergedefaults(defs, prob.p, parameters(prob.f.sys))
131+
defs = mergedefaults(defs, p, parameters(prob.f.sys))
132+
defs = mergedefaults(defs, prob.u0, states(prob.f.sys))
133+
defs = mergedefaults(defs, u0, states(prob.f.sys))
134+
135+
u0 = varmap_to_vars(u0, states(prob.f.sys); defaults = defs, tofloat = true)
136+
p = varmap_to_vars(p, parameters(prob.f.sys); defaults = defs)
137+
138+
return p, u0
120139
end
121140

122141
struct IsHistory end

0 commit comments

Comments
 (0)