Thanks a lot! So the first example is fixed, but there are more issues with the latest version of ModelingToolkit.
I have this code:
# Example two: Falling mass, attached to linear spring
using ModelingToolkit, OrdinaryDiffEq, LinearAlgebra
G_EARTH::Vector{Float64} = [0.0, 0.0, -9.81] # gravitational acceleration [m/sĀ²]
L0::Float64 = -10.0 # initial spring length [m]
# defing the model, Z component upwards
@parameters mass=1.0 c_spring=50.0 damping=0.5 l0=L0
@independent_variables t
@variables pos(t)[1:3] = [0.0, 0.0, L0]
@variables vel(t)[1:3] = [0.0, 0.0, 0.0]
@variables acc(t)[1:3] = G_EARTH
@variables unit_vector(t)[1:3] = [0.0, 0.0, -sign(L0)]
@variables spring_force(t)[1:3] = [0.0, 0.0, 0.0]
@variables norm1(t) = abs(l0) spring_vel(t) = 0.0
D = Differential(t)
eqs = vcat(D(pos) ~ vel,
D(vel) ~ acc,
norm1 ~ norm(pos),
unit_vector ~ -pos/norm1, # direction from point mass to origin
spring_vel ~ -unit_vector ā
vel,
spring_force ~ (c_spring * (norm1 - abs(l0)) + damping * spring_vel) * unit_vector,
acc ~ G_EARTH + spring_force/mass)
@named sys = ODESystem(eqs, t)
simple_sys = structural_simplify(sys)
# running the simulation
duration = 10.0
dt = 0.02
tol = 1e-6
tspan = (0.0, duration)
ts = 0:dt:duration
prob = ODEProblem(simple_sys, nothing, tspan)
@time sol = solve(prob, Rodas5(), dt=dt, abstol=tol, reltol=tol, saveat=ts)
nothing
It works fine with older versions of ModelingToolkit, with the latest version I get this output:
julia> include("src/Tether_02.jl")
ā Warning: Internal error: Variable (pos(t))[1] was marked as being in 0 ~ sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - norm1(t), but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/jEIdO/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[2] was marked as being in 0 ~ sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - norm1(t), but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/jEIdO/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[3] was marked as being in 0 ~ sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - norm1(t), but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/jEIdO/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (unit_vector(t))[1] was marked as being in 0 ~ -spring_vel(t) + (broadcast(-, unit_vector(t)))[1]*(vel(t))[1] + (broadcast(-, unit_vector(t)))[2]*(vel(t))[2] + (broadcast(-, unit_vector(t)))[3]*(vel(t))[3], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/jEIdO/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (unit_vector(t))[2] was marked as being in 0 ~ -spring_vel(t) + (broadcast(-, unit_vector(t)))[1]*(vel(t))[1] + (broadcast(-, unit_vector(t)))[2]*(vel(t))[2] + (broadcast(-, unit_vector(t)))[3]*(vel(t))[3], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/jEIdO/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (unit_vector(t))[3] was marked as being in 0 ~ -spring_vel(t) + (broadcast(-, unit_vector(t)))[1]*(vel(t))[1] + (broadcast(-, unit_vector(t)))[2]*(vel(t))[2] + (broadcast(-, unit_vector(t)))[3]*(vel(t))[3], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/jEIdO/src/structural_transformation/utils.jl:233
0.280586 seconds (727.74 k allocations: 41.242 MiB, 3.02% gc time, 95.96% compilation time)
Any idea? Is this a bug in ModelingToolkit, or is something wrong with my code?
@ChrisRackauckas Any comment?