The System type
ModelingToolkit.jl uses System to symbolically represent all types of numerical problems. Users create Systems representing the problem they want to solve and mtkcompile transforms them into a format ModelingToolkit.jl can generate code for (alongside performing other optimizations).
ModelingToolkitBase.System — Type
struct System <: ModelingToolkitBase.IntermediateDeprecationSystemA symbolic representation of a numerical system to be solved. This is a recursive tree-like data structure - each system can contain additional subsystems. As such, it implements the AbstractTrees.jl interface to enable exploring the hierarchical structure.
Fields
tag::UInt64: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.A unique integer tag for the system.
eqs::Vector{Equation}: The equations of the system.
noise_eqs::Union{Nothing, VecOrMat{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}}: The noise terms for each equation of the system. This field is only used for flattened systems. To represent noise in a hierarchical system, use brownians. In a system withNequations andKindependent brownian variables, this should be anN x Kmatrix. In the special case whereN == Kand each equation has independent noise, this noise matrix is diagonal. Diagonal noise can be specified by providing anNlength vector. If this field isnothing, the system does not have noise.
jumps::Vector{Union{JumpProcesses.ConstantRateJump, JumpProcesses.MassActionJump, JumpProcesses.VariableRateJump}}: Jumps associated with the system. Each jump can be aVariableRateJump,ConstantRateJumporMassActionJump. SeeJumpProcesses.jlfor more information.MassActionJumps must usescale_rates = false(pre-scaled rate expressions); seeSymbolicMassActionJump.
constraints::Vector{Union{Equation, Inequality}}: The constraints of the system. This can be used to represent the constraints in an optimal-control problem or boundary-value differential equation, or the constraints in a constrained optimization.
costs::Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}: The costs of the system. This can be the cost in an optimal-control problem, or the loss of an optimization problem. Scalar loss values must also be provided as a single- element vector.
consolidate::Any: A function which combines costs into a scalar value. This should take two arguments, thecostsof this system and the consolidated costs of all subsystems in the order they are present in thesystemsfield. It should return a scalar cost that combines all of the individual values. This defaults to a function that simply sums all cost values.
unknowns::Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}: The variables being solved for by this system. For example, in a differential equation system, this contains the dependent variables.
ps::Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}: The parameters of the system. Parameters can either be variables that parameterize the problem being solved for (e.g. the spring constant of a mass-spring system) or additional unknowns not part of the main dynamics of the system (e.g. discrete/clocked variables in a hybrid ODE).
brownians::Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}: The brownian variables of the system, created via@brownians. Each brownian variable represents an independent noise. A system with brownians cannot be simulated directly. It needs to be compiled usingmtkcompileintonoise_eqs.
poissonians::Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}: The poissonian variables of the system, created via@poissonians. Each poissonian variable represents an independent Poisson counting process with an associated rate. A system with poissonians cannot be simulated directly. It needs to be compiled usingmtkcompilewhich converts poissonians into jump equations.
iv::Union{Nothing, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}: The independent variable for a time-dependent system, ornothingfor a time-independent system.
observed::Vector{Equation}: Equations that compute variables of a system that have been eliminated from the set of unknowns bymtkcompile. More generally, this contains all variables that can be computed from the unknowns and parameters and do not need to be solved for. Such variables are termed as "observables". Each equation must be of the formobservable ~ expressionand observables cannot appear on the LHS of multiple equations. Equations must be sorted such that every observable appears on the left hand side of an equation before it appears on the right hand side of any other equation.
var_to_name::Dict{Symbol, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.A mapping from the name of a variable to the actual symbolic variable in the system. This is used to enable
getpropertysyntax to access variables of a system.
name::Symbol: The name of the system.
description::String: An optional description for the system.
bindings::ReadOnlyDicts.ReadOnlyDict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, ModelingToolkitBase.AtomicArrayDict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, Dict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}}}: Binding relations for variables/parameters. The bound variable (key) is completely determined by the binding (value). Providing an initial condition for a bound variable is an error. Bindings for variables (ones created via@variablesand@discretes) are treated as initial conditions.
initial_conditions::ModelingToolkitBase.AtomicArrayDict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, Dict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}}: Initial conditions for variables (unknowns/observables/parameters) which can be changed/overridden. When constructing a numerical problem from the system.
guesses::ModelingToolkitBase.AtomicArrayDict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, Dict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}}: Guess values for variables of a system that are solved for during initialization.
systems::Vector{System}: A list of subsystems of this system. Used for hierarchically building models.
initialization_eqs::Vector{Equation}: Equations that must be satisfied during initialization of the numerical problem created from this system. For time-dependent systems, these equations are not valid after the initial time.
continuous_events::Vector{ModelingToolkitBase.SymbolicContinuousCallback}: Symbolic representation of continuous events in a dynamical system. SeeSymbolicContinuousCallback.
discrete_events::Vector{ModelingToolkitBase.SymbolicDiscreteCallback}: Symbolic representation of discrete events in a dynamica system. SeeSymbolicDiscreteCallback.
connector_type::Any: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.If this system is a connector, the type of connector it is.
assertions::Dict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, String}: A map from expressions that must be through throughout the solution process to an associated error message. By default these assertions cause the generated code to outputNaNs if violated, but can be made to error usingdebug_system.
metadata::Base.ImmutableDict{DataType, Any}: The metadata associated with this system, as aBase.ImmutableDict. This follows the same interface as SymbolicUtils.jl. Metadata can be queried and updated usingSymbolicUtils.getmetadataandSymbolicUtils.setmetadatarespectively.
gui_metadata::Any: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.Metadata added by the
@mtkmodelmacro.
is_dde::Bool: Whether the system contains delay terms. This is inferred from the equations, but can also be provided explicitly.
tstops::Vector{Any}: Extra time points for the integrator to stop at. These can be numeric values, or expressions of parameters and time.
inputs::OrderedCollections.OrderedSet{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.The list of input variables of the system.
outputs::OrderedCollections.OrderedSet{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.The list of output variables of the system.
tearing_state::Any: TheTearingStateof the system post-simplification withmtkcompile.
namespacing::Bool: Whether the system namespaces variables accessed viagetproperty.completed systems do not namespace, but this flag can be toggled independently ofcompleteusingtoggle_namespacing.
complete::Bool: Whether the system is marked as "complete". Completed systems cannot be used as subsystems.
index_cache::Union{Nothing, ModelingToolkitBase.IndexCache}: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.For systems simplified or completed with
split = true(the default) this contains anIndexCachewhich aids in symbolic indexing. If this field isnothing, the system is either not completed, or completed withsplit = false.
parameter_bindings_graph::Union{Nothing, ModelingToolkitBase.ParameterBindingsGraph}: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.Contains the dependency graph of bound parameters to avoid excessive duplicated work during code generation.
ignored_connections::Union{Nothing, Vector{Connection}}: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.Connections that should be ignored because they were removed by an analysis point transformation. The first element of the tuple contains all such "standard" connections (ones between connector systems) and the second contains all such causal variable connections.
preface::Any:SymbolicUtils.Code.Assignments to prepend to all code generated from this system.
parent::Union{Nothing, System}: After simplification withmtkcompile, this field contains the unsimplified system with the hierarchical structure. There may be multiple levels ofparents. The root parent is used for accessing variables viagetpropertysyntax.
initializesystem::Union{Nothing, System}: A custom initialization system to use if no initial conditions are provided for the unknowns or observables of this system.
is_initializesystem::Bool: Whether the current system is an initialization system.
is_discrete::Boolstate_priorities::ModelingToolkitBase.AtomicArrayDict{Int64, Dict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, Int64}}: State priorities for variables. Used in structural simplification algorithms.
irreducibles::ModelingToolkitBase.AtomicArraySet{Dict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, Nothing}}: Variables marked as irreducible for simplification.
maybe_zeros::ModelingToolkitBase.AtomicArraySet{Dict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, Nothing}}: Expressions which may be zero and should be given special consideration during simplification.
irstructure::IRStructure{SymReal}: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.The
IRStructureused for efficient symbolic manipulation.
isscheduled::Bool: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.Whether the system has been simplified by
mtkcompile.
schedule::Union{Nothing, ModelingToolkitBase.Schedule}: This field is internal API. It may be removed or changed without notice in a non-breaking release. Usage of this field is not advised.The
Schedulecontaining additional information about the simplified system.
ModelingToolkitBase.AbstractSystem — Type
abstract type AbstractSystemAbstract supertype of all system types. Any custom system types must subtype this.
Utility constructors
Several utility constructors also exist to easily construct alternative system formulations.
ModelingToolkitBase.NonlinearSystem — Function
NonlinearSystem(sys::System) -> System
Given a time-dependent system sys of ODEs, convert it to a time-independent system of nonlinear equations that solve for the steady-state of the unknowns. This is done by replacing every derivative D(x) of an unknown x with zero. Note that this process does not retain noise equations, brownian terms, jumps or costs associated with sys. All other information such as initial conditions, bindings, guesses, observed and initialization equations are retained. The independent variable of sys becomes a parameter of the returned system.
If sys is hierarchical (it contains subsystems) this transformation will be applied recursively to all subsystems. The output system will be marked as complete if and only if the input system is also complete. This also retains the split flag passed to complete.
See also: complete.
ModelingToolkitBase.SDESystem — Function
SDESystem(eqs::Vector{Equation}, noise, iv; is_scalar_noise = false, kwargs...)Construct a system of equations with associated noise terms. Instead of specifying noise using @brownians variables, it is specified using a noise matrix noise. iv is the independent variable of the system.
In the general case, noise should be a N x M matrix where N is the number of equations (length(eqs)) and M is the number of independent random variables. noise[i, j] is the diffusion term for equation i and random variable j. If the noise is diagonal (N == M and noise[i, j] == 0 for all i != j) it can be specified as a Vector of length N corresponding to the diagonal of the noise matrix. As a special case, if all equations have the same noise then all rows of noise are identical. This is known as "scalar noise". In this case, noise can be a Vector corresponding to the repeated row and is_scalar_noise must be true.
Note that systems created in this manner cannot be used hierarchically. This should only be used to construct flattened systems. To use such a system hierarchically, it must be converted to use brownian variables using noise_to_brownians. mtkcompile will automatically perform this conversion.
All keyword arguments are the same as those of the System constructor.
SDESystem(eqs::Vector{Equation}, noise, iv, dvs, ps; is_scalar_noise = false, kwargs...)Identical to the 3-argument SDESystem constructor, but uses the explicitly provided dvs and ps for unknowns and parameters of the system.
SDESystem(sys::System, noise; kwargs...) -> System
Attach the given noise matrix noise to the system sys.
ModelingToolkitBase.JumpSystem — Function
JumpSystem(jumps, iv; kwargs...) -> System
Construct a System to solve a system of jump equations. jumps is an array of jumps, expressed using JumpProcesses.ConstantRateJump, JumpProcesses.VariableRateJump, and JumpProcesses.MassActionJump. It can also include standard equations to simulate jump-diffusion processes. iv should be the independent variable of the system.
MassActionJumps must be constructed with scale_rates = false (pre-scaled rate expressions). Use SymbolicMassActionJump for convenience, which handles this automatically. JumpProcesses will not re-apply factorial scaling on parameter updates for jumps constructed through the MTK pipeline.
All keyword arguments are the same as those of the System constructor.
JumpSystem(jumps, iv, dvs, ps; kwargs...)
Identical to the 2-argument JumpSystem constructor, but uses the explicitly provided dvs and ps for unknowns and parameters of the system.
See the 2-argument JumpSystem for details on MassActionJump requirements.
ModelingToolkitBase.OptimizationSystem — Function
OptimizationSystem(cost; kwargs...)
Construct a time-independent System for optimizing the specified scalar cost. The system will have no equations.
Unknowns and parameters of the system are inferred from the cost and other values (such as initial conditions) passed to it.
All keyword arguments are the same as those of the System constructor.
OptimizationSystem(cost, dvs, ps; kwargs...)
Identical to the corresponding single-argument OptimizationSystem constructor, except the unknowns and parameters are specified by passing arrays of symbolic variables to dvs and ps respectively.
OptimizationSystem(cost::Array; kwargs...)
Construct a time-independent System for optimizing the specified multi-objective cost. The cost will be reduced to a scalar using the consolidate function. This defaults to summing the specified cost and that of all subsystems. The system will have no equations.
Unknowns and parameters of the system are inferred from the cost and other values (such as initial conditions) passed to it.
All keyword arguments are the same as those of the System constructor.
OptimizationSystem(cost::Array, dvs, ps; kwargs...)
Identical to the corresponding single-argument OptimizationSystem constructor, except the unknowns and parameters are specified by passing arrays of symbolic variables to dvs and ps respectively.
Accessor functions
Several accessor functions exist to query systems for the information they contain. In general, for every field x there exists a has_x function which checks if the system contains the field and a get_x function for obtaining the value in the field. Note that fields of a system cannot be accessed via getproperty - that is reserved for accessing variables, subsystems or analysis points of the hierarchical system.
ModelingToolkitBase.has_eqs — Function
has_eqs(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field eqs.
See also get_eqs.
ModelingToolkitBase.get_eqs — Function
get_eqs(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field eqs of a system sys. It only includes eqs local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_eqs.
ModelingToolkitBase.equations — Function
equations(sys::AbstractSystem)Get the flattened equations of the system sys and its subsystems. It may include some abbreviations and aliases of observables. It is often the most useful way to inspect the equations of a system.
See also full_equations and ModelingToolkitBase.get_eqs.
ModelingToolkitBase.equations_toplevel — Function
equations_toplevel(sys::AbstractSystem)Replicates the behaviour of equations, but ignores equations of subsystems.
Notes:
- Cannot be applied to non-complete systems.
ModelingToolkitBase.full_equations — Function
full_equations(
sys::ModelingToolkitBase.AbstractSystem;
simplify
) -> Any
Like equations(sys), but also substitutes the observed equations eliminated from the equations during mtkcompile. These equations matches generated numerical code.
See also equations and ModelingToolkitBase.get_eqs.
ModelingToolkitBase.has_noise_eqs — Function
has_noise_eqs(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field noise_eqs.
See also get_noise_eqs.
ModelingToolkitBase.get_noise_eqs — Function
get_noise_eqs(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field noise_eqs of a system sys. It only includes noise_eqs local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_noise_eqs.
ModelingToolkitBase.has_jumps — Function
has_jumps(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field jumps.
See also get_jumps.
ModelingToolkitBase.get_jumps — Function
get_jumps(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field jumps of a system sys. It only includes jumps local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_jumps.
ModelingToolkitBase.jumps — Function
jumps(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the flattened jumps of the system. In other words, obtain all of the jumps in sys and all the subsystems of sys (appropriately namespaced).
ModelingToolkitBase.has_constraints — Function
has_constraints(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field constraints.
See also get_constraints.
ModelingToolkitBase.get_constraints — Function
get_constraints(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field constraints of a system sys. It only includes constraints local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_constraints.
ModelingToolkitBase.constraints — Function
constraints(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get all constraints in the system sys and all of its subsystems, appropriately namespaced.
ModelingToolkitBase.has_costs — Function
has_costs(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field costs.
See also get_costs.
ModelingToolkitBase.get_costs — Function
get_costs(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field costs of a system sys. It only includes costs local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_costs.
ModelingToolkitBase.cost — Function
cost(
sys::ModelingToolkitBase.AbstractSystem
) -> SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}
Recursively consolidate the cost vector of sys and all subsystems of sys, returning the final scalar cost function.
ModelingToolkitBase.has_consolidate — Function
has_consolidate(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field consolidate.
See also get_consolidate.
ModelingToolkitBase.get_consolidate — Function
get_consolidate(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field consolidate of a system sys. It only includes consolidate local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_consolidate.
ModelingToolkitBase.has_unknowns — Function
has_unknowns(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field unknowns.
See also get_unknowns.
ModelingToolkitBase.get_unknowns — Function
get_unknowns(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field unknowns of a system sys. It only includes unknowns local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_unknowns.
ModelingToolkitBase.unknowns — Function
unknowns(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the unknown variables of the system sys and its subsystems. These must be explicitly solved for, unlike observables(sys).
See also ModelingToolkitBase.get_unknowns.
ModelingToolkitBase.unknowns_toplevel — Function
unknowns_toplevel(sys::AbstractSystem)Replicates the behaviour of unknowns, but ignores unknowns of subsystems.
ModelingToolkitBase.has_ps — Function
has_ps(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field ps.
See also get_ps.
ModelingToolkitBase.get_ps — Function
get_ps(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field ps of a system sys. It only includes ps local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_ps.
ModelingToolkitBase.parameters — Function
parameters(
sys::ModelingToolkitBase.AbstractSystem;
initial_parameters
) -> Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}
Get the parameters of the system sys and its subsystems.
See also @parameters and ModelingToolkitBase.get_ps.
ModelingToolkitBase.parameters_toplevel — Function
parameters_toplevel(sys::AbstractSystem)Replicates the behaviour of parameters, but ignores parameters of subsystems.
ModelingToolkitBase.tunable_parameters — Function
tunable_parameters(sys, p = parameters(sys; initial_parameters = true); default=true)Get all parameters of sys that are marked as tunable.
Keyword argument default indicates whether variables without tunable metadata are to be considered tunable or not.
Create a tunable parameter by
@parameters u [tunable=true]For systems created with split = true (the default) and default = true passed to this function, the order of parameters returned is the order in which they are stored in the tunables portion of MTKParameters. Note that array variables will not be scalarized. To obtain the flattened representation of the tunables portion, call Symbolics.scalarize(tunable_parameters(sys)) and concatenate the resulting arrays.
See also getbounds, istunable, MTKParameters, complete
ModelingToolkitBase.has_brownians — Function
has_brownians(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field brownians.
See also get_brownians.
ModelingToolkitBase.get_brownians — Function
get_brownians(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field brownians of a system sys. It only includes brownians local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_brownians.
ModelingToolkitBase.brownians — Function
brownians(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get all of the brownian variables involved in the system sys and all subsystems, appropriately namespaced.
ModelingToolkitBase.has_iv — Function
has_iv(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field iv.
See also get_iv.
ModelingToolkitBase.get_iv — Function
get_iv(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field iv of a system sys. It only includes iv local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_iv.
ModelingToolkitBase.has_observed — Function
has_observed(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field observed.
See also get_observed.
ModelingToolkitBase.get_observed — Function
get_observed(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field observed of a system sys. It only includes observed local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_observed.
ModelingToolkitBase.observed — Function
observed(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the observed equations of the system sys and its subsystems. These can be expressed in terms of unknowns(sys), and do not have to be explicitly solved for.
See also observables and ModelingToolkitBase.get_observed().
ModelingToolkitBase.observables — Function
observables(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the observed variables of the system sys and its subsystems. These can be expressed in terms of unknowns(sys), and do not have to be explicitly solved for. It is equivalent to all left hand sides of observed(sys).
See also observed.
ModelingToolkitBase.has_name — Function
has_name(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field name.
See also get_name.
ModelingToolkitBase.get_name — Function
get_name(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field name of a system sys. It only includes name local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_name.
Base.nameof — Function
nameof(sys::ModelingToolkitBase.AbstractSystem) -> Any
Obtain the name of sys.
ModelingToolkitBase.has_description — Function
has_description(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field description.
See also get_description.
ModelingToolkitBase.get_description — Function
get_description(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field description of a system sys. It only includes description local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_description.
ModelingToolkitBase.description — Function
description(sys::ModelingToolkitBase.AbstractSystem) -> Any
Obtain the description associated with sys if present, and an empty string otherwise.
ModelingToolkitBase.bindings — Function
bindings(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the bindings of a system sys and its subsystems.
ModelingToolkitBase.has_initial_conditions — Function
has_initial_conditions(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field initial_conditions.
See also get_initial_conditions.
ModelingToolkitBase.get_initial_conditions — Function
get_initial_conditions(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field initial_conditions of a system sys. It only includes initial_conditions local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_initial_conditions.
ModelingToolkitBase.initial_conditions — Function
initial_conditions(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the initial conditions of a system sys and its subsystems.
ModelingToolkitBase.has_guesses — Function
has_guesses(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field guesses.
See also get_guesses.
ModelingToolkitBase.get_guesses — Function
get_guesses(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field guesses of a system sys. It only includes guesses local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_guesses.
ModelingToolkitBase.guesses — Function
guesses(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the guesses for variables in the initialization system of the system sys and its subsystems.
See also initialization_equations and ModelingToolkitBase.get_guesses.
ModelingToolkitBase.get_systems — Function
get_systems(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field systems of a system sys. It only includes systems local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_systems.
ModelingToolkitBase.has_initialization_eqs — Function
has_initialization_eqs(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field initialization_eqs.
See also get_initialization_eqs.
ModelingToolkitBase.get_initialization_eqs — Function
get_initialization_eqs(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field initialization_eqs of a system sys. It only includes initialization_eqs local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_initialization_eqs.
ModelingToolkitBase.initialization_equations — Function
initialization_equations(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the initialization equations of the system sys and its subsystems.
See also guesses, initial_conditions and ModelingToolkitBase.get_initialization_eqs.
ModelingToolkitBase.has_continuous_events — Function
has_continuous_events(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field continuous_events.
See also get_continuous_events.
ModelingToolkitBase.get_continuous_events — Function
get_continuous_events(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field continuous_events of a system sys. It only includes continuous_events local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_continuous_events.
ModelingToolkitBase.continuous_events — Function
continuous_events(sys::AbstractSystem)::Vector{SymbolicContinuousCallback}Returns a vector of all the continuous_events in an abstract system and its component subsystems. The SymbolicContinuousCallbacks in the returned vector are structs with two fields: eqs and affect which correspond to the first and second elements of a Pair used to define an event, i.e. eqs => affect.
See also get_continuous_events, which only returns the events of the top-level system.
ModelingToolkitBase.continuous_events_toplevel — Function
continuous_events_toplevel(sys::AbstractSystem)Replicates the behaviour of continuous_events, but ignores events of subsystems.
Notes:
- Cannot be applied to non-complete systems.
ModelingToolkitBase.has_discrete_events — Function
has_discrete_events(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field discrete_events.
See also get_discrete_events.
ModelingToolkitBase.get_discrete_events — Function
get_discrete_events(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field discrete_events of a system sys. It only includes discrete_events local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_discrete_events.
ModelingToolkitBase.discrete_events_toplevel — Function
discrete_events_toplevel(sys::AbstractSystem)Replicates the behaviour of discrete_events, but ignores events of subsystems.
Notes:
- Cannot be applied to non-complete systems.
ModelingToolkitBase.has_assertions — Function
has_assertions(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field assertions.
See also get_assertions.
ModelingToolkitBase.get_assertions — Function
get_assertions(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field assertions of a system sys. It only includes assertions local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_assertions.
ModelingToolkitBase.assertions — Function
assertions(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the assertions for a system sys and its subsystems.
ModelingToolkitBase.has_metadata — Function
has_metadata(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field metadata.
See also get_metadata.
ModelingToolkitBase.get_metadata — Function
get_metadata(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field metadata of a system sys. It only includes metadata local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_metadata.
SymbolicUtils.getmetadata — Method
getmetadata(
sys::ModelingToolkitBase.AbstractSystem,
k::DataType,
default
) -> Any
Get the metadata associated with key k in system sys or default if it does not exist.
SymbolicUtils.setmetadata — Method
setmetadata(
sys::ModelingToolkitBase.AbstractSystem,
k::DataType,
v
) -> Any
Set the metadata associated with key k in system sys to value v. This is an out-of-place operation, and will return a shallow copy of sys with the appropriate metadata values.
ModelingToolkitBase.has_is_dde — Function
has_is_dde(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field is_dde.
See also get_is_dde.
ModelingToolkitBase.get_is_dde — Function
get_is_dde(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field is_dde of a system sys. It only includes is_dde local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_is_dde.
ModelingToolkitBase.is_dde — Function
is_dde(sys::AbstractSystem)Return a boolean indicating whether a system represents a set of delay differential equations.
ModelingToolkitBase.has_tstops — Function
has_tstops(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field tstops.
See also get_tstops.
ModelingToolkitBase.get_tstops — Function
get_tstops(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field tstops of a system sys. It only includes tstops local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_tstops.
ModelingToolkitBase.symbolic_tstops — Function
symbolic_tstops(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the tstops present in sys and its subsystems, appropriately namespaced.
ModelingToolkitBase.has_tearing_state — Function
has_tearing_state(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field tearing_state.
See also get_tearing_state.
ModelingToolkitBase.get_tearing_state — Function
get_tearing_state(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field tearing_state of a system sys. It only includes tearing_state local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_tearing_state.
ModelingToolkitBase.does_namespacing — Function
does_namespacing(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Check whether a system performs namespacing.
ModelingToolkitBase.toggle_namespacing — Function
toggle_namespacing(
sys::ModelingToolkitBase.AbstractSystem,
value::Bool;
safe
) -> Any
Return a new sys with namespacing enabled or disabled, depending on value. The keyword argument safe denotes whether systems that do not support such a toggle should error or be ignored.
ModelingToolkitBase.iscomplete — Function
iscomplete(sys::ModelingToolkitBase.AbstractSystem) -> Any
Check whether a system is marked as complete.
ModelingToolkitBase.has_preface — Function
has_preface(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field preface.
See also get_preface.
ModelingToolkitBase.get_preface — Function
get_preface(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field preface of a system sys. It only includes preface local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_preface.
ModelingToolkitBase.preface — Function
preface(sys::ModelingToolkitBase.AbstractSystem) -> Any
Obtain the preface associated with sys and all of its subsystems, appropriately namespaced.
ModelingToolkitBase.has_parent — Function
has_parent(sys::ModelingToolkitBase.AbstractSystem) -> Bool
Returns whether the system sys has the internal field parent.
See also get_parent.
ModelingToolkitBase.get_parent — Function
get_parent(sys::ModelingToolkitBase.AbstractSystem) -> Any
Get the internal field parent of a system sys. It only includes parent local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_parent.
ModelingToolkitBase.has_initializesystem — Function
has_initializesystem(
sys::ModelingToolkitBase.AbstractSystem
) -> Bool
Returns whether the system sys has the internal field initializesystem.
See also get_initializesystem.
ModelingToolkitBase.get_initializesystem — Function
get_initializesystem(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Get the internal field initializesystem of a system sys. It only includes initializesystem local to sys; not those of its subsystems, like unknowns(sys), parameters(sys) and equations(sys) does.
See also has_initializesystem.
ModelingToolkitBase.is_initializesystem — Function
is_initializesystem(
sys::ModelingToolkitBase.AbstractSystem
) -> Any
Check if the given system is an initialization system.
getproperty syntax
ModelingToolkit allows obtaining in a system using getproperty. For a system sys with a subcomponent inner containing variable var, sys.inner.var will obtain the appropriately namespaced version of var. Note that this can also be used to access subsystems (sys.inner) or analysis points.
By default, top-level systems not marked as complete will apply their namespace. Systems marked as complete will not do this namespacing. This namespacing behavior can be toggled independently of whether the system is completed using toggle_namespacing and the current namespacing behavior can be queried via ModelingToolkit.does_namespacing.
Base.getproperty — Method
Base.getproperty(sys::AbstractSystem, name::Symbol)Access the subsystem, variable or analysis point of sys named name. To check if sys will namespace the returned value, use ModelingToolkitBase.does_namespacing(sys).
See also: ModelingToolkitBase.does_namespacing.
Functions for querying system equations
ModelingToolkitBase.has_diff_eqs — Function
has_diff_eqs(sys::AbstractSystem)Return true if a system contains at least one differential equation (i.e. an equation with a differential term). Note that this does not consider subsystems, and only takes into account equations in the top-level system.
Example:
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D
@parameters p d
@variables X(t)
eq1 = D(X) ~ p - d*X
eq2 = 0 ~ p - d*X
@named osys1 = tem([eq1], t)
@named osys2 = tem([eq2], t)
osys12 = compose(osys1, [osys2])
osys21 = compose(osys2, [osys1])
has_diff_eqs(osys12) # returns `true`.
has_diff_eqs(osys21) # returns `false`.ModelingToolkitBase.has_alg_eqs — Function
has_alg_eqs(sys::AbstractSystem)For a system, returns true if it contain at least one algebraic equation (i.e. that does not contain any differentials) in its top-level system.
Example:
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D
@parameters p d
@variables X(t)
eq1 = D(X) ~ p - d*X
eq2 = 0 ~ p - d*X
@named osys1 = System([eq1], t)
@named osys2 = System([eq2], t)
osys12 = compose(osys1, [osys2])
osys21 = compose(osys2, [osys1])
has_alg_eqs(osys12) # returns `false`.
has_alg_eqs(osys21) # returns `true`.ModelingToolkitBase.get_diff_eqs — Function
get_diff_eqs(sys::AbstractSystem)For a system, returns a vector of all differential equations (i.e. that does contain a differential) in its top-level system.
Example:
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D
@parameters p d
@variables X(t)
eq1 = D(X) ~ p - d*X
eq2 = 0 ~ p - d*X
@named osys1 = tem([eq1], t)
@named osys2 = tem([eq2], t)
osys12 = compose(osys1, [osys2])
osys21 = compose(osys2, [osys1])
get_diff_eqs(osys12) # returns `[Differential(t)(X(t)) ~ p - d*X(t)]`.
get_diff_eqs(osys21) # returns `Equation[]``.ModelingToolkitBase.get_alg_eqs — Function
get_alg_eqs(sys::AbstractSystem)For a system, returns a vector of all algebraic equations (i.e. that does not contain any differentials) in its top-level system.
Example:
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D
@parameters p d
@variables X(t)
eq1 = D(X) ~ p - d*X
eq2 = 0 ~ p - d*X
@named osys1 = ([eq1], t)
@named osys2 = ([eq2], t)
osys12 = compose(sys1, [osys2])
osys21 = compose(osys2, [osys1])
get_alg_eqs(osys12) # returns `Equation[]`.
get_alg_eqs(osys21) # returns `[0 ~ p - d*X(t)]`.ModelingToolkitBase.has_diff_equations — Function
has_diff_equations(sys::AbstractSystem)For a system, returns true if it contain at least one differential equation (i.e. that contain a differential).
Example:
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D
@parameters p d
@variables X(t)
eq1 = D(X) ~ p - d*X
eq2 = 0 ~ p - d*X
@named osys1 = System([eq1], t)
@named osys2 = System([eq2], t)
has_diff_equations(osys1) # returns `true`.
has_diff_equations(osys2) # returns `false`.ModelingToolkitBase.has_alg_equations — Function
has_alg_equations(sys::AbstractSystem)For a system, returns true if it contain at least one algebraic equation (i.e. that does not contain any differentials).
Example:
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D
@parameters p d
@variables X(t)
eq1 = D(X) ~ p - d*X
eq2 = 0 ~ p - d*X
@named osys1 = System([eq1], t)
@named osys2 = System([eq2], t)
has_alg_equations(osys1) # returns `false`.
has_alg_equations(osys2) # returns `true`.ModelingToolkitBase.diff_equations — Function
diff_equations(sys::AbstractSystem)For a system, returns a vector of all its differential equations (i.e. that does contain a differential).
Example:
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D
@parameters p d
@variables X(t)
eq1 = D(X) ~ p - d*X
eq2 = 0 ~ p - d*X
@named osys = System([eq1, eq2], t)
diff_equations(osys) # returns `[Differential(t)(X(t)) ~ p - d*X(t)]`.ModelingToolkitBase.alg_equations — Function
alg_equations(sys::AbstractSystem)For a system, returns a vector of all its algebraic equations (i.e. that does not contain any differentials).
Example:
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D
@parameters p d
@variables X(t)
eq1 = D(X) ~ p - d*X
eq2 = 0 ~ p - d*X
@named osys = System([eq1, eq2], t)
alg_equations(osys) # returns `[0 ~ p - d*X(t)]`.ModelingToolkitBase.is_alg_equation — Function
is_alg_equation(eq)Return true if the input is an algebraic equation, i.e. an equation that does not contain any differentials.
Example:
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D
@parameters p d
@variables X(t)
eq1 = D(X) ~ p - d*X
eq2 = 0 ~ p - d*X
is_alg_equation(eq1) # false
is_alg_equation(eq2) # trueModelingToolkitBase.is_diff_equation — Function
is_diff_equation(eq)Return true if the input is a differential equation, i.e. an equation that contains a differential term.
Example:
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D
@parameters p d
@variables X(t)
eq1 = D(X) ~ p - d*X
eq2 = 0 ~ p - d*X
is_diff_equation(eq1) # true
is_diff_equation(eq2) # falseString parsing
ModelingToolkit can parse system variables from strings.
ModelingToolkitBase.parse_variable — Function
parse_variable(
sys::ModelingToolkitBase.AbstractSystem,
str::AbstractString
) -> Any
Return the variable in sys referred to by its string representation str. Roughly supports the following CFG:
varname = "D(" varname ")" | "Differential(" iv ")(" varname ")" | arrvar | maybe_dummy_var
arrvar = maybe_dummy_var "[idxs...]"
idxs = int | int "," idxs
maybe_dummy_var = namespacedvar | namespacedvar "(" iv ")" |
namespacedvar "(" iv ")" "ˍ" ts | namespacedvar "ˍ" ts |
namespacedvar "ˍ" ts "(" iv ")"
ts = iv | iv ts
namespacedvar = ident "₊" namespacedvar | ident "." namespacedvar | identWhere iv is the independent variable, int is an integer and ident is an identifier.
Dumping system data
ModelingToolkitBase.dump_unknowns — Function
dump_unknowns(sys::AbstractSystem)Return an array of NamedTuples containing the metadata associated with each unknown in sys. Also includes the default value of the unknown, if provided.
using ModelingToolkitBase
using DynamicQuantities
using ModelingToolkitBase: t, D
@parameters p = 1.0, [description = "My parameter", tunable = false] q = 2.0, [description = "Other parameter"]
@variables x(t) = 3.0 [unit = u"m"]
@named sys = System(Equation[], t, [x], [p, q])
ModelingToolkitBase.dump_unknowns(sys)See also: ModelingToolkitBase.dump_variable_metadata, ModelingToolkitBase.dump_parameters
ModelingToolkitBase.dump_parameters — Function
dump_parameters(sys::AbstractSystem)Return an array of NamedTuples containing the metadata associated with each parameter in sys. Also includes the default value of the parameter, if provided.
using ModelingToolkitBase
using DynamicQuantities
using ModelingToolkitBase: t, D
@parameters p = 1.0, [description = "My parameter", tunable = false] q = 2.0, [description = "Other parameter"]
@variables x(t) = 3.0 [unit = u"m"]
@named sys = System(Equation[], t, [x], [p, q])
ModelingToolkitBase.dump_parameters(sys)See also: ModelingToolkitBase.dump_variable_metadata, ModelingToolkitBase.dump_unknowns
ModelingToolkitBase.dump_variable_metadata — Function
dump_variable_metadata(var)Return all the metadata associated with symbolic variable var as a NamedTuple.
using ModelingToolkitBase
@parameters p::Int [description = "My description", bounds = (0.5, 1.5)]
ModelingToolkitBase.dump_variable_metadata(p)Inputs and outputs
ModelingToolkitBase.inputs — Function
inputs(sys)Return all variables that mare marked as inputs. See also unbound_inputs See also bound_inputs, unbound_inputs
ModelingToolkitBase.outputs — Function
outputs(sys)Return all variables that mare marked as outputs. See also unbound_outputs See also bound_outputs, unbound_outputs
ModelingToolkitBase.bound_inputs — Function
bound_inputs(sys)Return inputs that are bound within the system, i.e., internal inputs See also bound_inputs, unbound_inputs, bound_outputs, unbound_outputs
ModelingToolkitBase.unbound_inputs — Function
unbound_inputs(sys)Return inputs that are not bound within the system, i.e., external inputs See also bound_inputs, unbound_inputs, bound_outputs, unbound_outputs
ModelingToolkitBase.bound_outputs — Function
bound_outputs(sys)Return outputs that are bound within the system, i.e., internal outputs See also bound_inputs, unbound_inputs, bound_outputs, unbound_outputs
ModelingToolkitBase.unbound_outputs — Function
unbound_outputs(sys)Return outputs that are not bound within the system, i.e., external outputs See also bound_inputs, unbound_inputs, bound_outputs, unbound_outputs
ModelingToolkitBase.is_bound — Function
is_bound(sys, u)Determine whether input/output variable u is "bound" within the system, i.e., if it's to be considered internal to sys. A variable/signal is considered bound if it appears in an equation together with variables from other subsystems. The typical usecase for this function is to determine whether the input to an IO component is connected to another component, or if it remains an external input that the user has to supply before simulating the system.
See also bound_inputs, unbound_inputs, bound_outputs, unbound_outputs
Debugging utilities
ModelingToolkitBase.debug_system — Function
debug_system(sys::AbstractSystem; functions = [log, sqrt, (^), /, inv, asin, acos], error_nonfinite = true)Wrap functions in sys so any error thrown in them shows helpful symbolic-numeric information about its input. If error_nonfinite, functions that output nonfinite values (like Inf or NaN) also display errors, even though the raw function itself does not throw an exception (like 1/0). For example:
julia> sys = debug_system(complete(sys))
julia> prob = ODEProblem(sys, [0.0, 2.0], (0.0, 1.0))
julia> prob.f(prob.u0, prob.p, 0.0)
ERROR: Function /(1, sin(P(t))) output non-finite value Inf with input
1 => 1
sin(P(t)) => 0.0Additionally, all assertions in the system are optionally logged when they fail. A new parameter is also added to the system which controls whether the message associated with each assertion will be logged when the assertion fails. This parameter defaults to true and can be toggled by symbolic indexing with ModelingToolkitBase.ASSERTION_LOG_VARIABLE. For example, prob.ps[ModelingToolkitBase.ASSERTION_LOG_VARIABLE] = false will disable logging.
Input validation
The following values can be passed to the check keyword of System to toggle validation of input. Flags can be combined with bitwise | and &.
ModelingToolkitBase.CheckAll — Constant
const CheckAllValue that can be provided to the check keyword of System to enable all input validation.
ModelingToolkitBase.CheckNone — Constant
const CheckNoneValue that can be provided to the check keyword of System to disable checking of input.
ModelingToolkitBase.CheckComponents — Constant
const CheckComponentsValue that can be provided to the check keyword of System to only enable checking of basic components of the system, such as equations, variables, etc.
ModelingToolkitBase.CheckUnits — Constant
const CheckUnitsValue that can be provided to the check keyword of System to enable checking of units.
These can also be used by custom AbstractSystem subtypes.
Utility functions
These utility functions can be useful when manipulating systems, especially when building custom AbstractSystem subtypes.
ModelingToolkitBase.collect_scoped_vars! — Function
collect_scoped_vars!(
unknowns::OrderedCollections.OrderedSet{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}},
parameters::OrderedCollections.OrderedSet{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}},
sys::ModelingToolkitBase.AbstractSystem,
iv::Union{Nothing, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}};
...
)
collect_scoped_vars!(
unknowns::OrderedCollections.OrderedSet{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}},
parameters::OrderedCollections.OrderedSet{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}},
sys::ModelingToolkitBase.AbstractSystem,
iv::Union{Nothing, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}},
::Type{op};
depth
)
Search through equations and parameter dependencies of sys, where sys is at a depth of depth from the root system, looking for variables scoped to the root system. Also recursively searches through all subsystems of sys, increasing the depth if it is not -1. A depth of -1 indicates searching for variables with GlobalScope.
Missing docstring for ModelingToolkit.collect_var_to_name!. Check Documenter's build log for details.
ModelingToolkitBase.collect_vars! — Function
collect_vars!(
unknowns::OrderedCollections.OrderedSet{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}},
parameters::OrderedCollections.OrderedSet{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}},
expr::SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal},
iv::Union{Nothing, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}};
...
)
collect_vars!(
unknowns::OrderedCollections.OrderedSet{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}},
parameters::OrderedCollections.OrderedSet{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}},
expr::SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal},
iv::Union{Nothing, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}},
::Type{op};
depth
)
Search through expr for all symbolic variables present in it. Populate dvs with unknowns and ps with parameters present. iv should be the independent variable of the system or nothing for time-independent systems. Expressions where the operator isa op go through validate_operator.
depth is a keyword argument which indicates how many levels down expr is from the root of the system hierarchy. This is used to resolve scoping operators. The scope of a variable can be checked using check_scope_depth.
This function should return nothing.
ModelingToolkitBase.eqtype_supports_collect_vars — Function
eqtype_supports_collect_vars(eq) -> Bool
Indicate whether the given equation type (Equation, Pair, etc) supports collect_vars!. Can be dispatched by higher-level libraries to indicate support.
ModelingToolkitBase.modified_unknowns! — Function
modified_unknowns!(
munknowns,
jump::Union{JumpProcesses.ConstantRateJump, JumpProcesses.VariableRateJump},
sts
) -> Any
Push to munknowns the variables modified by jump jump. sts is the list of unknowns of the system. Return the modified munknowns.
Namespace manipulation
ModelingToolkit namespaces variables from subsystems when using them in a parent system to disambiguate from identically named variables in other subsystems or the parent system. The following functions are useful for manipulating namespacing functionality.
ModelingToolkitBase.renamespace — Function
renamespace(
sys,
x::SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}
) -> SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}
Namespace x with the name of sys.
renamespace(sys, ap::AnalysisPoint) -> AnalysisPoint
Namespace an AnalysisPoint by namespacing the involved systems and the name of the point.
ModelingToolkitBase.namespace_equations — Function
namespace_equations(sys::AbstractSystem)Return equations(sys), namespaced by the name of sys.
Linearization and Analysis
Functions for linearization and analysis of systems.
ModelingToolkit.linearization_ap_transform — Function
sys, input_vars, output_vars =linearization_ap_transform(
sys,
inputs::Union{Vector{Symbol}, Vector{AnalysisPoint}, Symbol, AnalysisPoint},
outputs,
loop_openings
) -> Tuple{Any, Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}, Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}}
Apply analysis-point transformations to prepare a system for linearization.
Returns
sys: The transformed system.input_vars: A vector of input variables corresponding to the input analysis points.output_vars: A vector of output variables corresponding to the output analysis points.
ModelingToolkit.get_sensitivity_function — Function
get_sensitivity_function(
sys::ModelingToolkitBase.AbstractSystem,
aps;
kwargs...
) -> Tuple{ModelingToolkit.LinearizationFunction{Vector{Int64}, Vector{Int64}, Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}, P, H, _A, J1, J2, J3, J4, IA, @NamedTuple{abstol::Float64, reltol::Float64, nlsolve_alg::Nothing}} where {P<:ODEProblem, H<:Union{Expr, ModelingToolkitBase.GeneratedFunctionWrapper}, _A, J1<:Union{Nothing, ModelingToolkit.PreparedJacobian{true, DifferentiationInterfaceForwardDiffExt.ForwardDiffTwoArgJacobianPrep{Nothing, C, Tuple{Nothing, Nothing}}, ModelingToolkit.var"#uff#6"{var"#70#fun"}, _A, ADTypes.AutoForwardDiff{nothing, Nothing}} where {C<:(ForwardDiff.JacobianConfig{T, _A, _B, <:Tuple{Any, Any}} where {T<:(ForwardDiff.Tag{F} where F<:ModelingToolkit.var"#uff#6"), _A, _B}), var"#70#fun", _A}}, J2<:Union{Nothing, ModelingToolkit.PreparedJacobian{true, P, F, B, ADTypes.AutoForwardDiff{nothing, Nothing}} where {P, F, B}}, J3<:Union{Nothing, ModelingToolkit.PreparedJacobian{true, DifferentiationInterfaceForwardDiffExt.ForwardDiffTwoArgJacobianPrep{Nothing, C, Tuple{Nothing, Nothing, Nothing}}, ModelingToolkit.var"#pff#7"{var"#71#fun", var"#72#setter"}, _A, ADTypes.AutoForwardDiff{nothing, Nothing}} where {C<:(ForwardDiff.JacobianConfig{T, _A, _B, <:Tuple{Any, Vector{T} where T<:(ForwardDiff.Dual{T, _A, _B} where {_B, _A, T})}} where {T<:(ForwardDiff.Tag{F} where F<:(ModelingToolkit.var"#pff#7"{_A, SymbolicIndexingInterface.OOPSetter{_A1, System, var"#s177"}} where {_A, _A1, T, var"#s177"<:AbstractVector{T}})), _A, _B}), var"#71#fun", var"#72#setter", _A}}, J4<:(ModelingToolkit.PreparedJacobian{true, DifferentiationInterfaceForwardDiffExt.ForwardDiffTwoArgJacobianPrep{Nothing, C, Tuple{Nothing, Nothing, Nothing}}, ModelingToolkit.var"#hpf#5"{fun, setter}, _A, ADTypes.AutoForwardDiff{nothing, Nothing}} where {C<:(ForwardDiff.JacobianConfig{T, _A, _B, <:Tuple{Any, Vector{T} where T<:(ForwardDiff.Dual{T, _A, _B} where {_B, _A, T<:(ForwardDiff.Tag{F} where F<:(ModelingToolkit.var"#hpf#5"{_A, SymbolicIndexingInterface.OOPSetter{_A1, System, var"#s177"}} where {_A, _A1, T, var"#s177"<:AbstractVector{T}}))})}} where {T<:(ForwardDiff.Tag{F} where F<:(ModelingToolkit.var"#hpf#5"{_A, SymbolicIndexingInterface.OOPSetter{_A1, System, var"#s177"}} where {_A, _A1, T, var"#s177"<:AbstractVector{T}})), _A, _B}), fun, setter, _A}), IA<:Union{SciMLBase.NoInit, SciMLBase.OverrideInit{Nothing, Nothing, Nothing}}}, System}
Return the sensitivity function for the analysis point(s) aps, and the modified system simplified with the appropriate inputs and outputs.
Keyword Arguments
loop_openings: A list of analysis points whose connections should be removed and the outputs set to the input as a part of the linear analysis.system_modifier: A function taking the transformed system and applying any additional transformations, returning the modified system. The modified system is passed tolinearization_function.
All other keyword arguments are forwarded to linearization_function.
ModelingToolkit.get_comp_sensitivity_function — Function
get_comp_sensitivity_function(
sys::ModelingToolkitBase.AbstractSystem,
aps;
kwargs...
) -> Tuple{ModelingToolkit.LinearizationFunction{Vector{Int64}, Vector{Int64}, Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}, P, H, _A, J1, J2, J3, J4, IA, @NamedTuple{abstol::Float64, reltol::Float64, nlsolve_alg::Nothing}} where {P<:ODEProblem, H<:Union{Expr, ModelingToolkitBase.GeneratedFunctionWrapper}, _A, J1<:Union{Nothing, ModelingToolkit.PreparedJacobian{true, DifferentiationInterfaceForwardDiffExt.ForwardDiffTwoArgJacobianPrep{Nothing, C, Tuple{Nothing, Nothing}}, ModelingToolkit.var"#uff#6"{var"#70#fun"}, _A, ADTypes.AutoForwardDiff{nothing, Nothing}} where {C<:(ForwardDiff.JacobianConfig{T, _A, _B, <:Tuple{Any, Any}} where {T<:(ForwardDiff.Tag{F} where F<:ModelingToolkit.var"#uff#6"), _A, _B}), var"#70#fun", _A}}, J2<:Union{Nothing, ModelingToolkit.PreparedJacobian{true, P, F, B, ADTypes.AutoForwardDiff{nothing, Nothing}} where {P, F, B}}, J3<:Union{Nothing, ModelingToolkit.PreparedJacobian{true, DifferentiationInterfaceForwardDiffExt.ForwardDiffTwoArgJacobianPrep{Nothing, C, Tuple{Nothing, Nothing, Nothing}}, ModelingToolkit.var"#pff#7"{var"#71#fun", var"#72#setter"}, _A, ADTypes.AutoForwardDiff{nothing, Nothing}} where {C<:(ForwardDiff.JacobianConfig{T, _A, _B, <:Tuple{Any, Vector{T} where T<:(ForwardDiff.Dual{T, _A, _B} where {_B, _A, T})}} where {T<:(ForwardDiff.Tag{F} where F<:(ModelingToolkit.var"#pff#7"{_A, SymbolicIndexingInterface.OOPSetter{_A1, System, var"#s177"}} where {_A, _A1, T, var"#s177"<:AbstractVector{T}})), _A, _B}), var"#71#fun", var"#72#setter", _A}}, J4<:(ModelingToolkit.PreparedJacobian{true, DifferentiationInterfaceForwardDiffExt.ForwardDiffTwoArgJacobianPrep{Nothing, C, Tuple{Nothing, Nothing, Nothing}}, ModelingToolkit.var"#hpf#5"{fun, setter}, _A, ADTypes.AutoForwardDiff{nothing, Nothing}} where {C<:(ForwardDiff.JacobianConfig{T, _A, _B, <:Tuple{Any, Vector{T} where T<:(ForwardDiff.Dual{T, _A, _B} where {_B, _A, T<:(ForwardDiff.Tag{F} where F<:(ModelingToolkit.var"#hpf#5"{_A, SymbolicIndexingInterface.OOPSetter{_A1, System, var"#s177"}} where {_A, _A1, T, var"#s177"<:AbstractVector{T}}))})}} where {T<:(ForwardDiff.Tag{F} where F<:(ModelingToolkit.var"#hpf#5"{_A, SymbolicIndexingInterface.OOPSetter{_A1, System, var"#s177"}} where {_A, _A1, T, var"#s177"<:AbstractVector{T}})), _A, _B}), fun, setter, _A}), IA<:Union{SciMLBase.NoInit, SciMLBase.OverrideInit{Nothing, Nothing, Nothing}}}, System}
Return the complementary sensitivity function for the analysis point(s) aps, and the modified system simplified with the appropriate inputs and outputs.
Keyword Arguments
loop_openings: A list of analysis points whose connections should be removed and the outputs set to the input as a part of the linear analysis.system_modifier: A function taking the transformed system and applying any additional transformations, returning the modified system. The modified system is passed tolinearization_function.
All other keyword arguments are forwarded to linearization_function.
ModelingToolkit.get_looptransfer_function — Function
get_looptransfer_function(
sys::ModelingToolkitBase.AbstractSystem,
aps;
kwargs...
) -> Tuple{ModelingToolkit.LinearizationFunction{Vector{Int64}, Vector{Int64}, Vector{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}, P, H, _A, J1, J2, J3, J4, IA, @NamedTuple{abstol::Float64, reltol::Float64, nlsolve_alg::Nothing}} where {P<:ODEProblem, H<:Union{Expr, ModelingToolkitBase.GeneratedFunctionWrapper}, _A, J1<:Union{Nothing, ModelingToolkit.PreparedJacobian{true, DifferentiationInterfaceForwardDiffExt.ForwardDiffTwoArgJacobianPrep{Nothing, C, Tuple{Nothing, Nothing}}, ModelingToolkit.var"#uff#6"{var"#70#fun"}, _A, ADTypes.AutoForwardDiff{nothing, Nothing}} where {C<:(ForwardDiff.JacobianConfig{T, _A, _B, <:Tuple{Any, Any}} where {T<:(ForwardDiff.Tag{F} where F<:ModelingToolkit.var"#uff#6"), _A, _B}), var"#70#fun", _A}}, J2<:Union{Nothing, ModelingToolkit.PreparedJacobian{true, P, F, B, ADTypes.AutoForwardDiff{nothing, Nothing}} where {P, F, B}}, J3<:Union{Nothing, ModelingToolkit.PreparedJacobian{true, DifferentiationInterfaceForwardDiffExt.ForwardDiffTwoArgJacobianPrep{Nothing, C, Tuple{Nothing, Nothing, Nothing}}, ModelingToolkit.var"#pff#7"{var"#71#fun", var"#72#setter"}, _A, ADTypes.AutoForwardDiff{nothing, Nothing}} where {C<:(ForwardDiff.JacobianConfig{T, _A, _B, <:Tuple{Any, Vector{T} where T<:(ForwardDiff.Dual{T, _A, _B} where {_B, _A, T})}} where {T<:(ForwardDiff.Tag{F} where F<:(ModelingToolkit.var"#pff#7"{_A, SymbolicIndexingInterface.OOPSetter{_A1, System, var"#s177"}} where {_A, _A1, T, var"#s177"<:AbstractVector{T}})), _A, _B}), var"#71#fun", var"#72#setter", _A}}, J4<:(ModelingToolkit.PreparedJacobian{true, DifferentiationInterfaceForwardDiffExt.ForwardDiffTwoArgJacobianPrep{Nothing, C, Tuple{Nothing, Nothing, Nothing}}, ModelingToolkit.var"#hpf#5"{fun, setter}, _A, ADTypes.AutoForwardDiff{nothing, Nothing}} where {C<:(ForwardDiff.JacobianConfig{T, _A, _B, <:Tuple{Any, Vector{T} where T<:(ForwardDiff.Dual{T, _A, _B} where {_B, _A, T<:(ForwardDiff.Tag{F} where F<:(ModelingToolkit.var"#hpf#5"{_A, SymbolicIndexingInterface.OOPSetter{_A1, System, var"#s177"}} where {_A, _A1, T, var"#s177"<:AbstractVector{T}}))})}} where {T<:(ForwardDiff.Tag{F} where F<:(ModelingToolkit.var"#hpf#5"{_A, SymbolicIndexingInterface.OOPSetter{_A1, System, var"#s177"}} where {_A, _A1, T, var"#s177"<:AbstractVector{T}})), _A, _B}), fun, setter, _A}), IA<:Union{SciMLBase.NoInit, SciMLBase.OverrideInit{Nothing, Nothing, Nothing}}}, System}
Return the loop-transfer function for the analysis point(s) aps, and the modified system simplified with the appropriate inputs and outputs.
Keyword Arguments
loop_openings: A list of analysis points whose connections should be removed and the outputs set to the input as a part of the linear analysis.system_modifier: A function taking the transformed system and applying any additional transformations, returning the modified system. The modified system is passed tolinearization_function.
All other keyword arguments are forwarded to linearization_function.
ModelingToolkit.get_sensitivity — Function
get_sensitivity(sys, ap::AnalysisPoint; kwargs)
get_sensitivity(sys, ap_name::Symbol; kwargs)Compute the sensitivity function in analysis point ap. The sensitivity function is obtained by introducing an infinitesimal perturbation d at the input of ap, linearizing the system and computing the transfer function between d and the output of ap.
Arguments:
kwargs: Are sent toModelingToolkit.linearize
See also get_comp_sensitivity, get_looptransfer.
ModelingToolkit.get_comp_sensitivity — Function
get_comp_sensitivity(sys, ap::AnalysisPoint; kwargs)
get_comp_sensitivity(sys, ap_name::Symbol; kwargs)Compute the complementary sensitivity function in analysis point ap. The complementary sensitivity function is obtained by introducing an infinitesimal perturbation d at the output of ap, linearizing the system and computing the transfer function between d and the input of ap.
Arguments:
kwargs: Are sent toModelingToolkit.linearize
See also get_sensitivity, get_looptransfer.
ModelingToolkit.get_looptransfer — Function
get_looptransfer(sys, ap::AnalysisPoint; kwargs)
get_looptransfer(sys, ap_name::Symbol; kwargs)Compute the (linearized) loop-transfer function in analysis point ap, from ap.out to ap.in.
Feedback loops often use negative feedback, and the computed loop-transfer function will in this case have the negative feedback included. Standard analysis tools often assume a loop-transfer function without the negative gain built in, and the result of this function may thus need negation before use.
Arguments:
kwargs: Are sent toModelingToolkit.linearize
See also get_sensitivity, get_comp_sensitivity, open_loop.
ModelingToolkitBase.open_loop — Function
open_loop(
sys,
ap::Union{Symbol, AnalysisPoint};
system_modifier
) -> Tuple{Any, Tuple{Any, Any}}
Apply LoopTransferTransform to the analysis point ap and return the result of apply_transformation.
Keyword Arguments
system_modifier: a function which takes the modified system and returns a new system with any required further modifications performed.