Utilities
Several convenience methods are included for plotting, checking models, and converting results.
Plotting
Basic plotting includes a recipe for Plots.jl for plotting results.
One additional argument is columns
for specifying which columns to plot. This can be a vector of integer column positions or names of channels.
plot
Plots.plot
— Function.plot(y::SimResult)
Plot y
with options. For detailed options, see the Plots.jl documentation.
using Plots
v = sim(Sims.Examples.Basics.Vanderpol(), 10.0)
plot(v)
z = sim(Sims.Examples.Lib.CauerLowPassAnalog(), 60.0)
plot(z)
plot(z, layout = 1, legend = true)
plot(z, columns = [2,4])
plot(z, columns = 2:4)
plot(z, columns = ["n1", "n2"])
Miscellaneous
@unknown
Sims.@unknown
— Macro.A macro to ease entry of many unknowns.
@unknown a1 a2 a3 ...
Arguments
a
: various representations of Unknowns:symbol
: equivalent tosymbol = Unknown()
symbol(val)
: equivalent tosymbol = Unknown(symbol, val)
symbol(x, y, z)
: equivalent tosymbol = Unknown(x, y, z)
For `symbol(
Effects
Creates one or more Unknowns
check
Sims.check
— Function.Prints the number of equations and the number of unknowns.
check(x)
Arguments
x
: a Model, EquationSet, Sim, or SimState
Returns
Nvar
: Number of floating point variablesNeq
: Number of equations
initialize!
Sims.initialize!
— Function.Experimental function to initialize models. CURRENTLY BROKEN!
initialize!(ss::SimState)
Arguments
ss::SimState
: the SimState to be initialized
Returns
::JuMP.Model
Details
initialize!
updates ss.y0
and ss.yp0
with values that satisfy the initial equations. If it does not converge, a warning is printed, and ss
is not changed.
JuMP.jl
must be installed along with a nonlinear solver like Ipopt.jl
or NLopt.jl
. The JuMP model is set up without an objective function. Linear equality constraints are added for each fixed
variable. Nonlinear equality constraints are added for each equation in the model (with some additional checking work, some of these could probably be converted to linear constraints).
Also, initialize!
only works for scalar models. Models with Unknown vector components don't work. Internally, .*
is replaced with *
. It's rather kludgy, but right now, JuMP doesn't support .*
. A better approach might be to fully flatten the model.
initialize!
only runs at the beginning of simulations. It does not run after Events.