Internals

Documentation for BondGraph.jl's internal functions.

See the Public Documentation section of the manual covering the public functions.

Contents

Index

Internal Interface

Bond graph utils

BondGraph.equalityeqsMethod
equalityeqs(con)

Create a list of equality equations from a given array of expressions.

Arguments:

  • con: Array of expressions.

Returns:

  • Array of equality equations.

Example:

julia> con = [a, b, c]

julia> eqs = equalityeqs(con)
julia> # eqs = [a ~ b, a ~ c]

julia> con = [a]

julia> eqs = equalityeqs(con)
julia> # eqs = []
BondGraph.flatinputMethod
flatinput(ps)

Flatten and process input systems and signs.

Arguments:

  • ps: Array of input systems or input vectors.

Returns:

  • Tuple containing the flattened input systems and corresponding signs.

Example:

julia> ps = [sys1, [-1, sys2], sys3]

julia> subsys, signs = flatinput(ps)
# subsys = [sys1, sys2, sys3]
# signs = [1, -1, 1]
BondGraph.isindependentMethod
isindependent(var::Num)

Check if a variable is independent.

Arguments:

  • var::Num: The variable to check.

Returns:

  • true if the variable is independent.
  • false if the variable is not independent.
BondGraph.sumvarMethod
sumvar(con)

Create a sum variable equation from a given array of expressions.

Arguments:

  • con: Array of expressions.

Returns:

  • Sum variable equation if the array is non-empty, otherwise an empty array.

Example:

julia>  con = [a, b, c]

julia>  eq = sumvar(con)
# eq = 0 ~ (a + b + c)

julia> con = []

julia> eq = sumvar(con)
# eq = []

Connection utils

BondGraph.add_idxMethod
add_idx(var, idx)

Adds an index to a variable by renaming it with the index appended to its name.

Arguments:

  • var: Variable to be indexed.
  • idx: Index to be added to the variable name.

Returns:

  • Indexed variable with the index appended to its name.

Example:

julia> x = Variable(:x)
julia> indexed_var = add_idx(x, 1)  # Renames "x" to "x1"
BondGraph.check_bg_conMethod
check_bg_con(connectionset)

Check if the connection set contains a bond-graph (bg) connection.

Arguments:

  • connectionset: ConnectionSet object.

Returns:

  • Boolean indicating whether the connection set contains a bond-graph connection.
BondGraph.gen_tp_con!Method
gen_tp_con!(eqs, sys, subsys)

Generates bond graph connections between a system and its sub-systems for the modulated gyrator and modulated transformer (two-port elements).

Arguments:

  • eqs: Array of equations to which the connections will be added.
  • sys: The main system to which the connections will be made.
  • subsys: Sub-systems to be connected to the main system.

Returns:

  • None

Example:

julia> eqs = Equation[]
julia> sys = ODESystem([:x, :y], [dx, dy])
julia> subsys = [ODESystem([:a], [da]), ODESystem([:b], [db])]
julia> gen_tp_con!(eqs, sys, subsys)
BondGraph.get_bg_connection_set!Method
get_bg_connection_set!(connectionsets)

Extracts the bond-graph (bg) connection sets from a list of connection sets.

Arguments:

  • connectionsets: Array of ConnectionSet objects.

Returns:

  • Array of ConnectionSet objects containing only the bond-graph connection sets.

Graph algorithm utils

BondGraph.csets2adjmtxMethod
csets2adjmtx(csets, str2con; filterstr="f(t)", filterflow=false)

Generates an adjacency matrix from connection sets and a dictionary.

Arguments:

  • csets: Array of connection sets.
  • str2con: Dictionary mapping connection set names to connection elements.
  • filterstr: String to filter connections by name (default: "f(t)").
  • filterflow: Boolean indicating whether to filter connections by flow (default: false).

Returns:

  • am: Adjacency matrix representing the connections between connection elements.

Example:

julia> csets = [ConnectionSet([:a], [:b]), ConnectionSet([:c], [:d])]
julia> str2con = csets2dict(csets)
julia> am = csets2adjmtx(csets, str2con)
BondGraph.csets2dictMethod
csets2dict(csets)

Converts connection sets to a dictionary.

Arguments:

  • csets: Array of connection sets.

Returns:

  • str2con: Dictionary mapping connection set names to connection elements.
BondGraph.generate_bg_eqs!Method
generate_bg_eqs!(connectionsets)

Generates bond graph equations from connection sets.

Arguments:

  • connectionsets: Array of connection sets.

Returns:

  • eqs: Array of equations representing the bond graph.
BondGraph.generate_graphFunction
generate_graph(mdl, var=:e; method=:stress)

Generates a graph visualization of the bond graph model.

Arguments:

  • mdl: Bond graph model.
  • var: Variable to visualize connections for. Can be :e (effort) or :f (flow). Default is :e.
  • method: Graph layout method. Default is :stress.

Example:

julia> generate_graph(mdl, var=:e, method=:stress)
BondGraph.get_sm_mtx!Method
get_sm_mtx!(am, idx2k, str2con)

Generates the signal matrix by modifying the adjacency matrix.

Arguments:

  • am: Adjacency matrix representing the connections between connection elements.
  • idx2k: Dictionary mapping indices to connection element keys.
  • str2con: Dictionary mapping connection set names to connection elements.

Returns:

  • sm: Signal matrix representing the connections with modified entries.

Example:

julia> am = [0 1 0; 0 0 1; 0 0 0]
julia> idx2k = Dict(1 => "a", 2 => "b", 3 => "c")
julia> str2con = Dict("a" => con1, "b" => con2, "c" => con3)
julia> sm = get_sm_mtx!(am, idx2k, str2con)

ODESystem utils

BondGraph.reducedobsMethod
reducedobs(sys::ODESystem; name)

Create a reduced ODESystem by substituting observed variables in the equations.

Arguments:

  • sys::ODESystem: The original ODESystem object.
  • name: Optional name for the reduced ODESystem.

Returns:

A reduced ODESystem object with observed variables substituted.

Example:

julia> sys = ODESystem([eq1, eq2], t)
julia> reduced_sys = reducedobs(sys; name = "Reduced System")
BondGraph.simplifysysMethod
simplifysys(sys::ODESystem; name)

Simplify an ODE system by expanding connections, performing structural simplification and reducing the observed variables.

Arguments:

  • sys::ODESystem: The ODE system to simplify.
  • name: Optional name for the simplified system.

Returns:

  • The simplified ODE system.
BondGraph.substitute_dictMethod
substitute_dict(O, expr, sub)

Substitute the variables in O with their corresponding values from the dictionary sub in the expression expr.

Arguments

  • O: The variable or expression to be substituted.
  • expr: The expression in which the substitution should be performed.
  • sub: A dictionary mapping variables to their corresponding values.

Returns

The expression expr with the variables in O substituted using the values from sub.

BondGraph.substitute_observedMethod
substitute_observed(eq::Equation, sys::ODESystem)

Substitute observed variables in the equation with their assigned values.

Arguments:

  • eq::Equation: The equation to be processed.
  • sys::ODESystem: The ODESystem object containing the observed variables.

Returns:

An equation with observed variables substituted by their assigned values.

Example:

julia> eq = @eq x'(t) = a * x(t) + b * y(t)
julia> sys = ODESystem([eq], t)
julia> substituted_eq = substitute_observed(eq, sys)