Skip to content

MTK v11 documentation -- System constructor? #4662

Description

@B-LIE

How is the System constructor meant to be used❓

I have looked into the System docstring:

using ModelingToolkit
?System

It seems like the new structure is as follows:

System(eqs, iv; kwargs)

where a number of kwargs are listed, and name is a required kwarg. Also, there are specialized structures (multiple dispatch, I assume), e.g.

System(eqs, iv, dvs, ps; kwargs)

In addition to the listed kwargs, the docstring states that field names can be used as keywords, e.g., unknowns and ps.

Question 1: I have tried both of the above constructor signatures. The second one (System(eqs,t,vars,params; name=name)) works, but I couldn't get the first one (System(eqs,t; name=name, unknowns=vars, ps=params)) to work.

Question 2: Is the recommended/"future proof" syntax the one with 2 positional arguments + kwargs? Or the one with 4 positional arguments (assuming DAEs).

Question 3: I have also tried to initialize a "state" (differential variable) with a symbolic expression...

# I have already defined rho and A in a @parameters block...

#Attempt 1
@variables m(t)=1.5*rho*A

# Attempt 2
System(eqs,t,vars,params;name=name, initialization_eqs=[m ~ 1.5*rho*A])

# Attempt 3
System(eqs,t,vars,params;name=name, initial_conditions=[m => 1.5*rho*A])

Attempts 1 & 2 kind of work if I do not specify values in the ODEProblem. However, they both fail with an error message of over-specification if I try to change the initial value of m in the ODEProblem.

Attempt 3, however, works.

... Does this imply that initial_conditions is the keyword to use for specifying initial values of variables? There is also a field guesses... is there any advantage in specifying guesses in the System constructor, instead of as metadata in the @variables begin...end block?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions