-
-
Notifications
You must be signed in to change notification settings - Fork 232
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
I need to integrate ODEs with splined input functions, which I pass as parameters. With version 9.15.0, this code works:
using Test
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations
using DataInterpolations: CubicSpline
@variables F(t)
@parameters Fspline
@register_symbolic Ffunc(t, spline)
ts = 0.0 : 0.01 : 1.0
Fs = ts .^ 2
Ffunc(t, spl) = spl(t) # evaluate spline
# evaluate splined F(t) through an ODESystem
@mtkbuild sys = ODESystem([F ~ Ffunc(t, Fspline)], t, [F], [Fspline])
prob = ODEProblem(sys, [], (0.0, 1.0), [Fspline => NaN]) # uninitialized problem
prob = remake(prob; p = [Fspline => CubicSpline(Fs, ts)])
sol = solve(prob)
@test sol(0.5, idxs=F) ≈ 0.5^2
But after the parameter type validation added in ea4d2fc and/or 6ae4b33, it fails with
ERROR: LoadError: TypeError: in validate_parameter_type, in Parameter Fspline, expected Real, got a value of type CubicSpline{Vector{Float64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Vector{Float64}, Vector{Float64}, Float64}
Stacktrace:
[1] validate_parameter_type(ic::ModelingToolkit.IndexCache, p::Num, index::ModelingToolkit.ParameterIndex{…}, val::CubicSpline{…})
@ ModelingToolkit C:\Users\herma\.julia\packages\ModelingToolkit\wkMEe\src\systems\parameter_buffer.jl:459
[2] remake_buffer(indp::ODEProblem{…}, oldbuf::ModelingToolkit.MTKParameters{…}, vals::Dict{…})
@ ModelingToolkit C:\Users\herma\.julia\packages\ModelingToolkit\wkMEe\src\systems\parameter_buffer.jl:487
[3] _updated_u0_p_symmap(prob::ODEProblem{…}, u0::Nothing, ::Val{…}, p::Dict{…}, ::Val{…})
@ SciMLBase C:\Users\herma\.julia\packages\SciMLBase\JUp1I\src\remake.jl:486
[4] _updated_u0_p_internal(prob::ODEProblem{…}, ::Missing, p::Vector{…}; interpret_symbolicmap::Bool, use_defaults::Bool)
@ SciMLBase C:\Users\herma\.julia\packages\SciMLBase\JUp1I\src\remake.jl:399
[5] _updated_u0_p_internal
@ C:\Users\herma\.julia\packages\SciMLBase\JUp1I\src\remake.jl:388 [inlined]
[6] #updated_u0_p#688
@ C:\Users\herma\.julia\packages\SciMLBase\JUp1I\src\remake.jl:548 [inlined]
[7] updated_u0_p
@ C:\Users\herma\.julia\packages\SciMLBase\JUp1I\src\remake.jl:529 [inlined]
[8] remake(prob::ODEProblem{…}; f::Missing, u0::Missing, tspan::Missing, p::Vector{…}, kwargs::Missing, interpret_symbolicmap::Bool, use_defaults::Bool, _kwargs::@Kwargs{})
@ SciMLBase C:\Users\herma\.julia\packages\SciMLBase\JUp1I\src\remake.jl:95
I have tried to
- declare
@parameters Fspline :: CubicSpline
or@parameters Fspline(..) :: CubicSpline
, - pass
Fspline => CubicSpline(Fs, ts)
toODEProblem
instead ofremake
, - evaluate
Fspline(t)
directly in the ODESystem equation, instead of throughFfunc(t, Fspline)
,
and mixes thereof, but I cannot seem to get it to work again. Maybe I am not doing it as I should.
Is it possible to make this work with the recent additions?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working