Skip to content

connector for nonlinear system #3288

Open
@weigao-123

Description

@weigao-123

Question❓
Is there any tutorial or maybe feature to support connector for pure nonlinear systems?

Explaination
According to the documentation, which says MTK could also for modeling NonlinearSystem besides ODESystem, but currently not supported with the macros, and this is fine if we can programmatically generate the system.
My scenario is that I still would like to use the acausal modeling benefiting from connector, but only nonlinear system instead of ode system. From my understanding based on this, it seems that connector only supports ODESystem, so is there any way that we can achieve this?

Example
Here is basically what I would like to do:

using ModelingToolkit

@connector Pin begin
    @variables begin
        v
        i, [connect = Flow]
    end
end

@named node1 = Pin()
println(node1)

and with the following errors:

ArgumentError: Variable v is not a function of independent variable t.

Stacktrace:
 [1] check_variables(dvs::Vector{SymbolicUtils.BasicSymbolic{Real}}, iv::SymbolicUtils.BasicSymbolic{Real})
   @ ModelingToolkit C:\Users\xxx\.julia\packages\ModelingToolkit\klLLV\src\utils.jl:151
 [2] ODESystem(tag::UInt64, deqs::Vector{Equation}, iv::SymbolicUtils.BasicSymbolic{Real}, dvs::Vector{SymbolicUtils.BasicSymbolic{Real}}, ps::Vector{Any}, tspan::Nothing, var_to_name::Dict{Any, Any}, ctrls::Vector{Any}, observed::Vector{Equation}, tgrad::Base.RefValue{Vector{Num}}, jac::Base.RefValue{Any}, ctrl_jac::Base.RefValue{Any}, Wfact::Base.RefValue{Matrix{Num}}, Wfact_t::Base.RefValue{Matrix{Num}}, name::Symbol, description::String, systems::Vector{ODESystem}, defaults::Dict{Any, Any}, guesses::Dict{Any, Any}, torn_matching::Nothing, initializesystem::Nothing, initialization_eqs::Vector{Equation}, schedule::Nothing, connector_type::Nothing, preface::Nothing, cevents::Vector{ModelingToolkit.SymbolicContinuousCallback}, devents::Vector{ModelingToolkit.SymbolicDiscreteCallback}, parameter_dependencies::Vector{Equation}, metadata::Nothing, gui_metadata::ModelingToolkit.GUIMetadata, is_dde::Bool, tstops::Vector{Any}, tearing_state::Nothing, substitutions::Nothing, complete::Bool, index_cache::Nothing, discrete_subsystems::Nothing, solved_unknowns::Nothing, split_idxs::Nothing, parent::Nothing; checks::Bool)
   @ ModelingToolkit C:\Users\xxx\.julia\packages\ModelingToolkit\klLLV\src\systems\diffeqs\odesystem.jl:201
 [3] ODESystem
   @ C:\Users\xxx\.julia\packages\ModelingToolkit\klLLV\src\systems\diffeqs\odesystem.jl:189 [inlined]
 [4] ODESystem(deqs::Vector{Equation}, iv::Num, dvs::Vector{Any}, ps::Vector{Any}; controls::Vector{Num}, observed::Vector{Equation}, systems::Vector{ODESystem}, tspan::Nothing, name::Symbol, description::String, default_u0::Dict{Any, Any}, default_p::Dict{Any, Any}, defaults::Dict{Num, Union{Function, Number, Symbol}}, guesses::Dict{Any, Any}, initializesystem::Nothing, initialization_eqs::Vector{Equation}, schedule::Nothing, connector_type::Nothing, preface::Nothing, continuous_events::Nothing, discrete_events::Nothing, parameter_dependencies::Vector{Equation}, checks::Bool, metadata::Nothing, gui_metadata::ModelingToolkit.GUIMetadata, is_dde::Nothing, tstops::Vector{Any})
   @ ModelingToolkit C:\Users\xxx\.julia\packages\ModelingToolkit\klLLV\src\systems\diffeqs\odesystem.jl:302
 [5] __Pin__(; name::Symbol, v::ModelingToolkit.NoValue, i::ModelingToolkit.NoValue)
   @ Main C:\Users\xxx\.julia\packages\ModelingToolkit\klLLV\src\systems\model_parsing.jl:914
 [6] __Pin__
   @ C:\Users\xxx\.julia\packages\ModelingToolkit\klLLV\src\systems\model_parsing.jl:138 [inlined]
 [7] #_#440
   @ C:\Users\xxx\.julia\packages\ModelingToolkit\klLLV\src\systems\model_parsing.jl:25 [inlined]
 [8] top-level scope
   @ C:\Users\xxx\.julia\packages\ModelingToolkit\klLLV\src\systems\abstractsystem.jl:2060

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions