Hello everyone! I try to model simple internal ballistics model in ModelingToolkit.jl framework.
using ModelingToolkit, DifferentialEquations, Plots
begin
@variables t
D = Differential(t)
end
function terminate_affect!(integ, u, p, ctx)
terminate!(integ)
end
begin
@parameters κ1 λ1 μ1 κ2 λ2 μ2 Jk zk ν p_s ω f α θ ρ W0 qfi S pf pv ld
@variables ψ(t)=0.0 z(t)=0.0 p(t) v(t)=0.0 x(t)=0.0
end
eqs = [
D(ψ) ~ ifelse(
z < 1.0,
κ1 * (1. + 2*λ1 * z + 3 * μ1 * z^2) * D(z),
ifelse(
z < zk,
κ2 * (1. + 2*λ2 * (z-1) + 3 * μ2 * (z-1)^2) * D(z),
0
)
)
D(z) ~ ifelse(
z < zk,
ifelse(
p > p_s,
p / Jk,
(p_s^(1-ν) * p^ν) / Jk
),
0
)
p ~ pv + (f * ω * ψ - 0.5*θ*qfi*v^2) / (W0 - ω*(1-ψ)/ρ - ω*ψ*α + S * x)
D(v) ~ ifelse(
(p > pf)|(v>0),
p * S / qfi,
0
)
D(x) ~ v
]
@named intbal = ODESystem(
eqs, continuous_events=[z ~ zk=>z ~ zk, ψ~1=>ψ~1, (x - ld) ~ 0 => (terminate_affect!, [x], [], nothing)]
)
simp = structural_simplify(intbal)
pars = [
κ1=>0.239,
λ1=>2.26,
μ1=>0.0,
κ2=>0.835,
λ2=>-0.943,
μ2=>0.0,
Jk=>330.0e3,
p_s=>50e6,
ν=>0.75,
zk=>1.53,
f=>988e3,
ρ=>1600,
θ=>0.236,
α=>1.038e-3,
ω=>0.01,
W0=>0.125E-3,
qfi=>0.389,
S=>0.25*0.03^2*pi,
pf=>50e6,
pv=>4e6,
ld=>2.2
]
prob = ODEProblem(simp, [], (0.0, 0.05), pars)
The above code give me the following error
MethodError: no method matching -(::SymbolicUtils.BasicSymbolic{Real}, ::Symbolics.Equation)
Closest candidates are:
-(!Matched::MultivariatePolynomials.RationalPoly, ::Any)
@ MultivariatePolynomials ~/.julia/packages/MultivariatePolynomials/6TYc8/src/rational.jl:73
-(!Matched::ChainRulesCore.AbstractThunk, ::Any)
@ ChainRulesCore ~/.julia/packages/ChainRulesCore/0t04l/src/tangent_types/thunks.jl:34
-(!Matched::MultivariatePolynomials.AbstractPolynomialLike, ::Any)
@ MultivariatePolynomials ~/.julia/packages/MultivariatePolynomials/6TYc8/src/operators.jl:65
...
(::ModelingToolkit.var"#329#339")(::Symbolics.Equation)@callbacks.jl:381
iterate@generator.jl:47[inlined]
_collect(::Vector{Symbolics.Equation}, ::Base.Generator{Vector{Symbolics.Equation}, ModelingToolkit.var"#329#339"}, ::Base.EltypeUnknown, ::Base.HasShape{1})@array.jl:802
collect_similar@array.jl:711[inlined]
map@abstractarray.jl:3263[inlined]
var"#generate_rootfinding_callback#327"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(ModelingToolkit.generate_rootfinding_callback), ::Vector{ModelingToolkit.SymbolicContinuousCallback}, ::ModelingToolkit.ODESystem, ::Vector{Any}, ::Vector{SymbolicUtils.BasicSymbolic{Real}})@callbacks.jl:379
generate_rootfinding_callback@callbacks.jl:371[inlined]
var"#generate_rootfinding_callback#326"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(ModelingToolkit.generate_rootfinding_callback), ::ModelingToolkit.ODESystem, ::Vector{Any}, ::Vector{SymbolicUtils.BasicSymbolic{Real}})@callbacks.jl:368
generate_rootfinding_callback(::ModelingToolkit.ODESystem, ::Vector{Any}, ::Vector{SymbolicUtils.BasicSymbolic{Real}})@callbacks.jl:364
generate_rootfinding_callback(::ModelingToolkit.ODESystem)@callbacks.jl:364
var"#process_events#369"(::Nothing, ::Bool, ::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(ModelingToolkit.process_events), ::ModelingToolkit.ODESystem)@callbacks.jl:503
var"#_#586"(::Nothing, ::Bool, ::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::Type{SciMLBase.ODEProblem{true, SciMLBase.AutoSpecialize}}, ::ModelingToolkit.ODESystem, ::Vector{Any}, ::Tuple{Float64, Float64}, ::Vector{Pair{Symbolics.Num, Float64}})@abstractodesystem.jl:838
ODEProblem@abstractodesystem.jl:827[inlined]
#_#584@abstractodesystem.jl:814[inlined]
ODEProblem@abstractodesystem.jl:813[inlined]
#ODEProblem#583@abstractodesystem.jl:810[inlined]
ODEProblem@abstractodesystem.jl:809[inlined]
top-level scope@Local: 1[inlined]
Honestly, im not very common with Julia and with ModelingToolkit too. So I have no idea what the problem here