Hi,
I defined an ODE problem in ModelingToolkit.jl, as such:
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using ModelingToolkitStandardLibrary.Blocks
using DataInterpolations
using OrdinaryDiffEq
function System(input_funcs::Dict, params::Dict; name)
@named T_a_out = TimeVaryingFunction(input_funcs[:T_a])
@named Φ_hp_out = TimeVaryingFunction(input_funcs[:Φ_hp])
@named Φ_cv_out = TimeVaryingFunction(input_funcs[:Φ_cv])
@named Φ_s_out = TimeVaryingFunction(input_funcs[:Φ_s])
vars = @variables T_i(t) T_e(t) T_h(t) T_a(t) Φ_hp(t) Φ_cv(t) Φ_s(t)
pars = @parameters lC_i=params[:lC_i] lC_e=params[:lC_e] lC_h=params[:lC_h] lR_ie=params[:lR_ie] lR_ea=params[:lR_ea] lR_ih=params[:lR_ih] lA_w=params[:lA_w] lA_e=params[:lA_e]
# order p
p = [lC_i, lC_e, lC_h, lR_ie, lR_ea, lR_ih, lA_w, lA_e]
eqs = [
# inputs
T_a ~ T_a_out.output.u
Φ_hp ~ Φ_hp_out.output.u
Φ_cv ~ Φ_cv_out.output.u
Φ_s ~ Φ_s_out.output.u
# dynamics
exp(lC_i)*D(T_i) ~ exp(lA_w)*Φ_s + exp(-lR_ih)*(T_h - T_i) + exp(-lR_ie)*(T_e - T_i)
exp(lC_e)*D(T_e) ~ exp(lA_e)*Φ_s + exp(-lR_ea)*(T_a - T_e) + exp(-lR_ie)*(T_i - T_e)
exp(lC_h)*D(T_h) ~ Φ_cv + Φ_hp + exp(-lR_ih)*(T_i - T_h)
]
ODESystem(eqs, t, vars, p; systems = [T_a_out, Φ_hp_out, Φ_cv_out, Φ_s_out], name)
end
# input functions
T_a_linf = LinearInterpolation(T_a_data, time)
Φ_hp_linf = LinearInterpolation(Φ_hp_data, time)
Φ_cv_linf = LinearInterpolation(Φ_cv_data, time)
Φ_s_linf = LinearInterpolation(Φ_s_data, time)
input_funcs = Dict(
:T_a => T_a_linf,
:Φ_hp => Φ_hp_linf,
:Φ_cv => Φ_cv_linf,
:Φ_s => Φ_s_linf
)
@named system = System(input_funcs, params_d)
sys = structural_simplify(system)
prob = ODEProblem(sys, [T_bias, T_bias, T_bias], (0, time[end]))
I can solve this problem pretty easily, no issues at all:
sol = solve(prob, Tsit5());
But when I explicitly set the exact same parameters, in the same order, as an argument to the solver like this:
sol = solve(prob, Tsit5(); p=[
params_d[:lC_i],
params_d[:lC_e],
params_d[:lC_h],
params_d[:lR_ie],
params_d[:lR_ea],
params_d[:lR_ih],
params_d[:lA_w],
params_d[:lA_e]
])
I get a completely different solution.
What is going on here?