Solve
The solve function is the primary interface for solving ODE problems using various QSS (Quantized State Systems) algorithms. It does this by dispatching on the problem and algorithm types to select the right solver.
Based on the QSS Algorithm provided, the solve function either selects a basic QSS integration method or, in the case of LiQSS, constructs additional data structures needed for implicit integration. The method defaults to cycle detection (Val(2)), tolerances (abstol=1e-3 and reltol=1e-3), and a maximum number of iterations (maxiters=1e7). These parameters can be adjusted based on the problem's complexity and desired accuracy. When a user doesn't provide a solver explicitly, the solve function defaults to using the modified second-order implicit algorith (mLiQSS2).
Helper Functions:
createCommonData:
Sets up the common data required by the QSS solver. It initializes all necessary vectors (x, q, tx, tq, nextStateTime, etc.) used in the integration process, and it pre-allocates a cache of Taylor series to avoid repeated memory allocation during integration (taylorOpsCache).
getClosure:
Creates a closure for the Jacobian and the dependency matrices, allowing easy extension. The closure is used to access the Jacobian matrix during the integration process.
createLiqssData:
Initializes internal data structures required by LiQSS solvers for managing linear approximations. This function has two methods, depending on how the Jacobian is specified during problem definition (via the ODEProblem
function):
Symbolic Jacobian (:symbolic
):
createLiqssData(::Val{:symbolic}, ::Val{M}, ::Val{T}, ::Val{Order}) where {T, Order, M}
Constructs and returns an AexprLiQSS_data object, which stores symbolic expressions for the Jacobian entries.
Approximated Jacobian (:approximate
):
createLiqssData(::Val{:approximate}, ::Val{M}, ::Val{T}, ::Val{Order}) where {T, Order, M}
Constructs and returns an AmanualLiQSS_data object, which stores coefficient data to be used for the approximation of the jacobian entries.
Internals
QuantizedSystemSolver.custom_Solve
— Methodcustom_Solve(prob::ODEProblemData{F,PRTYPE,T,D,Z,CS},al::QSSAlgorithm{Solver, Order},::Val{M},finalTime::Float64,saveat::Float64,initialTime::Float64,abstol::Float64,reltol::Float64,maxErr::Float64,maxiters::Int,verbose::Bool) where{F,PRTYPE,T,D,Z,CS,Solver,Order,M}
default solve method: calls the integrator to solve the nonlinear ODE problem.
Arguments
prob::ODEProblemData{F,PRTYPE,T,D,Z,CS}
: The nonlinear ODE problem to solve.al::QSSAlgorithm{Solver, Order}
: The QSS algorithm to use for solving the problem.::Val{M}
: A type parameter indicating which detection mechanism to use.finalTime::Float64
: The final time for the simulation.saveat::Float64
: The time interval at which to save the solution.initialTime::Float64
: The initial time for the simulation.abstol::Float64
: The absolute tolerance for the solver.reltol::Float64
: The relative tolerance for the solver.maxErr::Float64
: The maximum allowable error.maxiters::Int
: The maximum number of iterations.
QuantizedSystemSolver.createCommonData
— MethodcreateCommonData(prob::ODEProblemData{F,PRTYPE,T,D,Z,CS},::Val{Order},finalTime::Float64,saveat::Float64,initialTime::Float64,abstol::Float64,reltol::Float64,maxErr::Float64,maxiters::Int,verbose::Bool) where{F,PRTYPE,T,D,Z,CS,Order}
creates the necessary data for the simulation and stores it in a CommonQSS_Data struct.
Arguments
prob::ODEProblemData{F,PRTYPE,T,D,Z,CS}
: The nonlinear ODE problem to solve.::Val{Order}
: The order of the algorithm.finalTime::Float64
: The final time for the simulation.saveat::Float64
: The time interval at which to save the solution.initialTime::Float64
: The initial time for the simulation.abstol::Float64
: The absolute tolerance for the solver.reltol::Float64
: The relative tolerance for the solver.maxErr::Float64
: The maximum allowable error.maxiters::Int
: The maximum number of iterations.
Returns
- A data structure containing common data required for the QSS algorithm.
QuantizedSystemSolver.createLiqssData
— MethodcreateLiqssData(::Val{:symbolic},::Val{M},::Val{T},::Val{Order}) where{T,Order,M}
Creates LIQSS-specific data required for solving an ODE problem.
Arguments
::Val{M}
: A type parameter indicating which detection mechanism to use.::Val{T}
: The number of continuous variables.::Val{Order}
: The order of the algorithm.
Returns
- A data structure containing LIQSS-specific data required for liQSS algorithms.
QuantizedSystemSolver.CommonQSS_Data
— TypeCommonQSS_Data{Z}
helper datastructures that hold settings, temporary saved data needed for simulation, and results.
QuantizedSystemSolver.LiQSS_Data
— TypeLiQSS_Data{O,M}
An abstract type representing the data structure for the LiQSS (Linearly Quantized State System) solver.
Type Parameters
O
: The type parameter representing the order of the QSS method.M
: The cycle detection mechanism number, which can be used to specify different cycle detection strategies.
QuantizedSystemSolver.AexprLiQSS_data
— TypeAexprLiQSS_data{O,M}
helper datastructures needed only for implicit case to store the Jacobian coefficients from an expression function. The field variables are:
cycleDetection::Val{M}
# cycle detection mechanismcacheA::MVector{1,Float64}
# the coef a is computed from a function and the result is saved in a chache.qaux::Vector{MVector{O,Float64}}
# to update u, q^- and dx^- are needed, so these 2 are to save the old valuesdxaux::Vector{MVector{O,Float64}}
# so these 2 are to save the old valuesolddx::Int64
# not needed for coefficient 'a' precomputed as expression, but kept for compatibility with parent type
QuantizedSystemSolver.AmanualLiQSS_data
— TypeAmanualLiQSS_data{O,M}
A data structure for storing information specific to the manual implementation of the LiQSS (Linear Quantized State System) method.
Type Parameters
O
: The order of the QSS method.M
: The cycle detection mechanism number.
Description
This struct extends LiQSS_Data
and is intended for use in scenarios where a manual computation of the jacobian coefficient is recommended or required. It includes fields for storing the cycle detection mechanism, coefficient 'a', auxiliary vectors for quantized states and old values, and an additional vector for storing old dx values.
The field variables are:
- `cycleDetection::Val{M}`: Cycle detection mechanism.
- `a::Vector{Vector{Float64}}`: Coefficient 'a' computed manually.
- `cacheA::Int64`: Not needed when coefficient 'a' is computed manually, but kept for compatibility with parent type.
- `qaux::Vector{MVector{O,Float64}}`: Auxiliary vectors to update `u`, `q^-`.
- `dxaux::Vector{MVector{O,Float64}}`: Auxiliary vectors `dx^- to save the old values (and high order derivatives).
- `olddx::Vector{MVector{1,Float64}}`: Needed to compute the coefficient 'a' manually, storing old dx values (only first derivative).
See Also