Skip to content
This repository was archived by the owner on Mar 27, 2022. It is now read-only.
This repository was archived by the owner on Mar 27, 2022. It is now read-only.

Cartesian pendulum #8

Description

@crlaugh

I tried to implement a single pendulum model in Cartesian coordinates, but got an error when I tried to instantiate it. Should this model work with the current release (0.7.2)?

using TinyModia
using ModiaBase
using ModiaPlot

# Cartesian pendulum model. 
CPendulum = Model(
    L = Var(1.0, parameter=true),
    m = Var(1.0, parameter=true),
    g_n = Var(9.80665, parameter=true),

    x = Var(init=1/sqrt(2)),
    y = Var(init=-1/sqrt(2)),
    vx = Var(),
    vy = Var(),
    F = Var(),
    
    equation = :[  
        der(x) = vx
        der(y) = vy
  
        m*der(vx) = (F/L)*x
        m*der(vy) = (F/L)*y - m*g_n
  
        x^2 + y^2 = L^2]
)

cPendulum = @instantiateModel(CPendulum)

When I try to instantiate this, I get

julia> cPendulum = @instantiateModel(CPendulum)

Instantiating model Main.CPendulum
ERROR: BoundsError: attempt to access 0-element Vector{Any} at index [1]
Stacktrace:
  [1] getindex
    @ .\array.jl:801 [inlined]
  [2] derivative(ex::Expr, timeInvariants::Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}})
    @ ModiaBase.Differentiate C:\Users\laughman\.julia\packages\ModiaBase\igtEB\src\Differentiate.jl:84
  [3] (::ModiaBase.Differentiate.var"#4#8"{Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}}})(e::Expr)
    @ ModiaBase.Differentiate .\none:0
  [4] iterate
    @ .\generator.jl:47 [inlined]
  [5] collect_to!(dest::Vector{Expr}, itr::Base.Generator{Vector{Any}, ModiaBase.Differentiate.var"#4#8"{Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}}}}, offs::Int64, st::Int64)
    @ Base .\array.jl:724
  [6] collect_to_with_first!(dest::Vector{Expr}, v1::Expr, itr::Base.Generator{Vector{Any}, ModiaBase.Differentiate.var"#4#8"{Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}}}}, st::Int64)
    @ Base .\array.jl:702
  [7] collect(itr::Base.Generator{Vector{Any}, ModiaBase.Differentiate.var"#4#8"{Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}}}})
    @ Base .\array.jl:683
  [8] derivative(ex::Expr, timeInvariants::Base.KeySet{Any, OrderedCollections.OrderedDict{Any, Any}})
    @ ModiaBase.Differentiate C:\Users\laughman\.julia\packages\ModiaBase\igtEB\src\Differentiate.jl:98
  [9] assignAndBLT(equations::Vector{Any}, unknowns::Vector{Any}, parameters::OrderedCollections.OrderedDict{Any, Any}, Avar::Vector{Int64}, G::Vector{Vector{Int64}}, states::Vector{Any}, logDetails::Bool, log::Bool, logTiming::Bool)
    @ TinyModia C:\Users\laughman\.julia\packages\TinyModia\yrVLj\src\TinyModia.jl:197
 [10] instantiateModel(model::NamedTuple{(:class, :L, :m, :g_n, :x, :y, :vx, :vy, :F, :equation), Tuple{Symbol, NamedTuple{(:class, :value, :parameter), Tuple{Symbol, Float64, Bool}}, NamedTuple{(:class, :value, :parameter), Tuple{Symbol, Float64, Bool}}, NamedTuple{(:class, :value, :parameter), Tuple{Symbol, Float64, Bool}}, NamedTuple{(:class, :init), Tuple{Symbol, Float64}}, NamedTuple{(:class, :init), Tuple{Symbol, Float64}}, NamedTuple{(:class,), Tuple{Symbol}}, NamedTuple{(:class,), Tuple{Symbol}}, NamedTuple{(:class,), Tuple{Symbol}}, Expr}}; modelName::String, modelModule::Module, source::String, FloatType::Type, aliasReduction::Bool, unitless::Bool, log::Bool, logModel::Bool, logDetails::Bool, logStateSelection::Bool, logCode::Bool, logExecution::Bool, logTiming::Bool)
    @ TinyModia C:\Users\laughman\.julia\packages\TinyModia\yrVLj\src\TinyModia.jl:847
 [11] top-level scope
    @ REPL[3]:1

Is TinyModia able to compile the Cartesian pendulum at this point, or is this functionality still in process?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions