Skip to contents

substitute_component(sys, old, new) returns sys with the subsystem old (obtained as sys$name, or sys$outer$name for a nested one) replaced by new, as substitute_component(sys, old => new) in ModelingToolkit. new must have the same name as the component it replaces and offer all of its unknowns, parameters and subsystems, with the same connector types and input or output markings, so that every connection to the component stays valid.

Usage

substitute_component(sys, old, new = NULL)

Arguments

sys

A hierarchical System that is not complete.

old

The subsystem to replace, namespaced by sys; or a list list(old, new).

new

The replacement system.

Value

The modified System.

Examples

t <- t_nounits; D <- D_nounits
x <- Variable("x", t); k <- Parameter("k")
decay <- System(list(D(x) ~ -k * x), t, name = "part")
growth <- System(list(D(x) ~ k * x), t, name = "part")
model <- System(list(), t, systems = list(decay), name = "model")
equations(substitute_component(model, model$part, growth))
#> [[1]]
#> Derivative(part₊x(t), t) ~ part₊k*part₊x(t) 
#>