Closed ufechner7 closed 3 months ago
It should be
eqs = reduce(vcat, Symbolics.scalarize.(eqs));
Thanks for suggesting this workaround. But it does not help:
# Example two: Falling mass, attached to linear spring
using ModelingToolkit, OrdinaryDiffEq, LinearAlgebra
using ModelingToolkit: t_nounits as t, D_nounits as D
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
@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 spring_vel(t) = 0.0
eqs = vcat(D(pos) ~ vel,
D(vel) ~ acc,
unit_vector ~ -pos/norm(pos), # direction from point mass to origin
spring_vel ~ -unit_vector ā
vel,
spring_force ~ (c_spring * (norm(pos) - abs(l0)) + damping * spring_vel) * unit_vector,
acc ~ G_EARTH + spring_force/mass)
eqs = reduce(vcat, Symbolics.scalarize.(eqs))
@named sys = ODESystem(eqs, t)
simple_sys = structural_simplify(sys)
nothing
Running this script gives even more error messages than before:
julia> include("mwes/mwe03.jl")
ā Warning: Internal error: Variable (pos(t))[2] was marked as being in 0 ~ -(unit_vector(t))[1] + (-(pos(t))[1]) / sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))), but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[3] was marked as being in 0 ~ -(unit_vector(t))[1] + (-(pos(t))[1]) / sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))), but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[1] was marked as being in 0 ~ -(unit_vector(t))[2] + (-(pos(t))[2]) / sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))), but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[3] was marked as being in 0 ~ -(unit_vector(t))[2] + (-(pos(t))[2]) / sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))), but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[1] was marked as being in 0 ~ -(unit_vector(t))[3] + (-(pos(t))[3]) / sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))), but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[2] was marked as being in 0 ~ -(unit_vector(t))[3] + (-(pos(t))[3]) / sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))), but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[1] was marked as being in 0 ~ -(spring_force(t))[1] + (c_spring*(sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - abs(l0)) + damping*spring_vel(t))*(unit_vector(t))[1], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[2] was marked as being in 0 ~ -(spring_force(t))[1] + (c_spring*(sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - abs(l0)) + damping*spring_vel(t))*(unit_vector(t))[1], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[3] was marked as being in 0 ~ -(spring_force(t))[1] + (c_spring*(sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - abs(l0)) + damping*spring_vel(t))*(unit_vector(t))[1], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[1] was marked as being in 0 ~ -(spring_force(t))[2] + (c_spring*(sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - abs(l0)) + damping*spring_vel(t))*(unit_vector(t))[2], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[2] was marked as being in 0 ~ -(spring_force(t))[2] + (c_spring*(sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - abs(l0)) + damping*spring_vel(t))*(unit_vector(t))[2], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[3] was marked as being in 0 ~ -(spring_force(t))[2] + (c_spring*(sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - abs(l0)) + damping*spring_vel(t))*(unit_vector(t))[2], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[1] was marked as being in 0 ~ -(spring_force(t))[3] + (c_spring*(sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - abs(l0)) + damping*spring_vel(t))*(unit_vector(t))[3], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[2] was marked as being in 0 ~ -(spring_force(t))[3] + (c_spring*(sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - abs(l0)) + damping*spring_vel(t))*(unit_vector(t))[3], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
ā Warning: Internal error: Variable (pos(t))[3] was marked as being in 0 ~ -(spring_force(t))[3] + (c_spring*(sqrt(Symbolics._mapreduce(#396, +, pos(t), Colon(), (:init => false,))) - abs(l0)) + damping*spring_vel(t))*(unit_vector(t))[3], but was actually zero
ā @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/GyyTb/src/structural_transformation/utils.jl:233
I am now using ModelingToolkit v9.30.1.
Can you please re-open this issue?
eqs = Symbolics.scalarize.(reduce(vcat, Symbolics.scalarize.(eqs)))
will work.
Describe the bug š
ModelingToolkit v9.28.0 prints a lot of warnings (Internal error) for a script that was running fine with older versions of ModelingToolkit.
Expected behavior
No warning for the code that worked before.
Minimal Reproducible Example š
Error & Stacktrace ā ļø
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
Additional context
The simulation result still looks correct.