User API
Problem definition
QuantizedSystemSolver.ODEProblem
— MethodODEProblem(f::Function, u::Vector{Float64}, tspan::Tuple{Float64,Float64}, p::Union{Vector{EM}, Tuple{Vararg{EM}}}) where{EM}
Creates an ODE problem with the given function f
, initial conditions u
, parameters p
, and time span tspan
.
Arguments
f::Function
: The function defining the ODE.u::Vector{Float64}
: The initial conditions.p::Vector{Float64}
: The parameters.tspan::Tuple{Float64,Float64}
: The time span for the ODE.
Returns
- An ODE problem.
QuantizedSystemSolver.ODEProblem
— MethodODEProblem(f::Function, u::Vector{Float64}, tspan::Tuple{Float64,Float64})
Creates an ODE problem with the given function f
, initial conditions u
, and time span tspan
.
Arguments
f::Function
: The function defining the ODE.u::Vector{Float64}
: The initial conditions.tspan::Tuple{Float64,Float64}
: The time span for the ODE.
Returns
- An ODE problem.
The solve function:
QuantizedSystemSolver.solve
— Methodsolve(prob::NLODEProblem{F,PRTYPE,T,D,Z,CS},al::QSSAlgorithm{SolverType, OrderType};detection::Val{M}=Val(3),saveat=Inf::Float64,abstol=1e-3::Float64,reltol=1e-2::Float64,maxErr=Inf::Float64,maxiters=Int(1e7)::Int) where{F,PRTYPE,T,D,Z,CS,SolverType,OrderType,M}
dispatches on a specific integrator based on the algorithm provided and send a nonlinear ODE problem to the integrator.
Arguments
prob::NLODEProblem{F,PRTYPE,T,D,Z,CS}
: The nonlinear ODE problem to solve.al::QSSAlgorithm{SolverType, OrderType}
: The QSS algorithm to use for solving the problem.detection::Val{M}
: A type parameter indicating which detection mechanism to use.saveat::Float64
: The time interval at which to save the solution (default:Inf
).abstol::Float64
: The absolute tolerance for the solver (default:1e-3
).reltol::Float64
: The relative tolerance for the solver (default:1e-2
).maxErr::Float64
: The maximum allowable error (default:Inf
).maxiters::Int
: The maximum number of iterations (default:Int(1e7)
).
QuantizedSystemSolver.solve
— Methodsolve(prob::NLODEProblem{F,PRTYPE,T,D,Z,CS},al::QSSAlgorithm{SolverType, OrderType},tspan::Tuple{Float64, Float64};detection::Val{M}=Val(3),saveat=Inf::Float64,abstol=1e-3::Float64,reltol=1e-2::Float64,maxErr=Inf::Float64,maxiters=Int(1e7)::Int) where{F,PRTYPE,T,D,Z,CS,SolverType,OrderType,M}
dispatches on a specific integrator based on the algorithm provided and send a nonlinear ODE problem to the integrator.
With the exception of the argument prob and tspan, all other arguments are optional and have default values:
- The algorithm defaults to nmliqss2, and it is specified by the QSSAlgorithm type, which is a composite type that has a name and an order. It can be extended independently of the solver.
- The detection argument defaults to 1.
- The saveat argument defaults to Inf. It specifies the time step at which the integrator will save the solution (not implemented).
- The abstol argument defaults to 1e-3. It specifies the absolute tolerance of the integrator.
- The reltol argument defaults to 1e-2. It specifies the relative tolerance of the integrator.
- The maxErr argument defaults to Inf. It specifies the maximum error allowed by the integrator. This is used as an upper bound for the quantum when a variable goes large.
- The maxiters argument defaults to 1e7. It specifies the maximum number of steps allowed by the integrator. If the user wants to extend the limit on the maximum number of steps, this argument can be used.
After the simulation, the solution is returned as a Solution object.
Algorithms
QuantizedSystemSolver.qss1
— Methodqss1()
calls the explicit quantized state system solver with order 1
qss1()=QSSAlgorithm(Val(:qss),Val(1))
QuantizedSystemSolver.qss2
— Methodqss2()
calls the explicit quantized state system solver with order 2
QuantizedSystemSolver.liqss1
— Methodliqss1()
calls the imlicit quantized state system solver with order 1.
QuantizedSystemSolver.liqss2
— Methodliqss2()
calls the imlicit quantized state system solver with order 2.
QuantizedSystemSolver.nmliqss1
— Methodnmliqss1()
calls the modified imlicit quantized state system solver with order 1. It is efficient when the system contains large entries outside the main diagonal of the Jacobian .
QuantizedSystemSolver.nmliqss2
— Methodnmliqss2()
calls the modified imlicit quantized state system solver with order 2. It is efficient when the system contains large entries outside the main diagonal of the Jacobian .
Solution
Query a solution
QuantizedSystemSolver.evaluateSol
— MethodevaluateSol(sol::Sol{T,O}, index::Int, t::Float64) where {T,O}
Evaluates the solution at a given time t
for a specified variable index.
Arguments
sol::Sol{T,O}
: The solution struct.index::Int
: The index of the variable to evaluate. Ifindex
is 0, evaluates all variables.t::Float64
: The time at which to evaluate the solution.
Returns
- The value of the specified variable at time
t
, or a vector of values ifindex
is 0.
Throws
- An error if the given time
t
is outside the solution range.
QuantizedSystemSolver.solInterpolated
— MethodsolInterpolated(sol::Sol{T,O},step::Float64) where {T,O}
Construct a new solution by interpolating the current solution at each step for all variables.
Arguments
sol::Sol{T,O}
: The solution struct.step::Float64
: the step size at which to generate the new solution.
Returns
- A new solution that contains information at each step size..
QuantizedSystemSolver.solInterpolated
— MethodsolInterpolated(sol::Sol{T,O},index::Int,step::Float64) where {T,O}
Constructs a new solution by interpolating the current solution at each step for one variable.
Arguments
sol::Sol{T,O}
: The solution struct.index::Int
: the index of the variable to interpolate.step::Float64
: the step size at which to generate the new solution.
Returns
- A new solution that contains the information of one variable at each step size.
Base.show
— Methodshow(io::IO, a::Stats)
Displays the statistics of the simulation.
Arguments
io::IO
: The IO stream to write to.a::Stats
: The Stats struct containing the simulation statistics.
Prints
- The total simulation steps.
- The simultaneous steps.
- The number of events.
QuantizedSystemSolver.Stats
— TypeStats
A struct that holds the statistics of a simulation. It has the following fields:
totalSteps::Int
: The total number of simulation steps.simulStepCount::Int
: The number of simultaneous steps.evCount::Int
: The number of events.numSteps::Vector{Int}
: A vector holding the number of steps for each variable.
Error with respect to an analytic or reference solution
To find the error, an interpolated solution has to be used as shown in solInterpolated
. The reference solution (using saveat for example) and the interpolated solution (passed step to interpolated function) must have the same tspan and the same step size.
QuantizedSystemSolver.getError
— MethodgetError(sol::Sol{T,O},index::Int,f::Function) where{T,O}
calculates the relative error of one variable of the solution with respect to a function of an analytic solution.
\[\begin{equation*} err=\sqrt{\frac{\sum(sol_{index}-f_{index})^2}{\sum(f_{index})^2}} \end{equation*}\]
QuantizedSystemSolver.getAverageError
— MethodgetAverageError(sol::Sol{T,O},f::Vector{Function}) where{T,O}
calculates the average relative error of all variables of the solution with respect to a vector of functions of analytic solutions.
\[\begin{align*} & err_{index}=\sqrt{\frac{\sum(sol_{index}-f_{index})^2}{\sum(f_{index})^2}}\ & avgError=\frac{\sum_{index=1}^{T}err_{index}}{T} \end{align*}\]
QuantizedSystemSolver.getErrorByRefs
— MethodgetErrorByRefs(sol::Sol{T,O},index::Int,solRef::Vector{Any}) where{T,O}
calculates the relative error of one variable of the solution with respect to a vector of values received from a reference solution.
\[\begin{equation*} err=\sqrt{\frac{\sum(sol_{index}-solRef_{index})^2}{\sum(solRef_{index})^2}} \end{equation*}\]
QuantizedSystemSolver.getAverageErrorByRefs
— MethodgetAverageErrorByRefs(sol::Sol{T,O},solRef::Vector{Any}) where{T,O}
calculates the average relative error of the solution with respect to a reference solution. The relative error is calculated for each variable, and then it is averaged over all variables.
\[\begin{align*} & err_{index}=\sqrt{\frac{\sum(sol_{index}-solRef_{index})^2}{\sum(solRef_{index})^2}}\ & avgError=\frac{\sum_{index=1}^{T}err_{index}}{T} \end{align*}\]
Plot the solution
RecipesBase.plot
— Methodplot(sol::Sol{T,O};idxs=Int[]::Vector{Int},note=" "::String,xlims=(0.0,0.0)::Tuple{Float64, Float64},ylims=(0.0,0.0)::Tuple{Float64, Float64},legend=:true::Bool,marker=:circle::Symbol,title="") where{T,O}
generates a plot of the solution of the system (returned as a plot object). With the exception of the solution object, all arguments are optional.
arguments:
sol::Sol{T,O}
: The solution struct.xvars::Int...
: The indices of the variables to plot. If no indices are provided, all variables are plotted.idxs::::Vector{Float64}
: The indices of the variables to plot. If no indices are provided, all variables are plotted.note::String
: A note to add to the title of the plot.xlims::Tuple{Float64, Float64}
: The x-axis limits of the plot.ylims::Tuple{Float64, Float64}
: The y-axis limits of the plot.legend::Bool
: A boolean indicating whether to display the legend.marker::Symbol
: The marker to use for the plot.title::String
: The title of the plot.
QuantizedSystemSolver.plot_Sol
— Methodplot_Sol(sol::Sol{T,O},xvars::Int...;note=" "::String,xlims=(0.0,0.0)::Tuple{Float64, Float64},ylims=(0.0,0.0)::Tuple{Float64, Float64},legend=:true::Bool,marker=:circle::Symbol,title="") where{T,O}
generates a plot of the solution of the system (returned as a plot object). With the exception of the solution object, all arguments are optional.
arguments:
sol::Sol{T,O}
: The solution struct.xvars::Int...
: The indices of the variables to plot. If no indices are provided, all variables are plotted.note::String
: A note to add to the title of the plot.xlims::Tuple{Float64, Float64}
: The x-axis limits of the plot.ylims::Tuple{Float64, Float64}
: The y-axis limits of the plot.legend::Bool
: A boolean indicating whether to display the legend.marker::Symbol
: The marker to use for the plot.title::String
: The title of the plot.
QuantizedSystemSolver.plot_SolSum
— Methodplot_SolSum(sol::Sol{T,O},xvars::Int...;interp=0.0001,note=" "::String,xlims=(0.0,0.0)::Tuple{Float64, Float64},ylims=(0.0,0.0)::Tuple{Float64, Float64},legend=:true::Bool) where{T,O}
plots of the sum of the variables xvars.
Arguments
sol::Sol{T,O}
: The solution struct.xvars::Int...
: The indices of the variables to sum. If no indices are provided, all variables are summed.interp::Float64
: The interpolation step.note::String
: A note to add to the title of the plot.xlims::Tuple{Float64, Float64}
: The x-axis limits of the plot.ylims::Tuple{Float64, Float64}
: The y-axis limits of the plot.legend::Bool
: A boolean indicating whether to display the legend.