Quantizer

The Quantizer functions

The system handles different quantizer orders (Order 1 and Order 2...). It defines methods for state integration, derivative computation, event time computation, updating quantized values, and cycle detection updates.

computeNextTime: for first-order, the state of the system changes at a constant rate. The core calculation takes place when the first derivative of the state, represented by $x[i][1]$, is non-zero. In this case, the function determines the time to the next event by dividing a quantum threshold by this derivative. Additionally, to prevent numerical issues, it ensures that this calculated time-step does not fall below a predefined minimum value, $absDeltaT$. If the first derivative is extremely small or essentially zero, the function adjusts it to avoid potential numerical instabilities that could arise from very small time increments.

For second-order, the system state evolves with both a rate of change (first derivative) and acceleration (second derivative). The core calculation occurs when the second derivative of the state, represented by $x[i][2]$, is non-zero. In this case, the function computes the time to the next event by using the square root of the ratio between a quantum threshold and the second derivative. This ensures that the time-step reflects the influence of the system's acceleration. Additionally, to prevent numerical issues (such as division by zero or overly small time-steps), a minimum delta time (absDeltaT) is enforced. If the computed time-step is smaller than this threshold, the function adjusts the second derivative to maintain stability. If the second derivative is zero but the first derivative is non-zero, the time to the next event is calculated based on the first derivative. The function ensures that the time-step does not drop below absDeltaT, adjusting the first derivative if necessary. If both derivatives are zero, the system is assumed to have no change, and the next event time is set to infinity (Inf).

recomputeNextTime: The reComputeNextTime functions are used in the explicit QSS algorithms to enable the recalculation of the next time after interactions between different variables, such as variable i and variable j. These functions determine the time until the system crosses the quantum threshold by solving polynomial equations derived from the difference between the quantized state and the actual state. In situations where the quantum threshold has already been surpassed, they promptly return a very small time increment (e.g., simt + 1e-12) to trigger an immediate update of the system's state.

LiqssrecomputeNextTime: In the LIQSS methods of first-order, the recomputeNextTime function calculates the next event time based on the current state (x), its first derivative (x1), and the quantized state (q). First, if the difference between the current state and the quantized state exceeds twice the quantum size, the next event is scheduled almost immediately with a small time-step. Otherwise, if the derivative is non-zero, the function computes the time-step by dividing the state difference by the derivative. If the result is positive, this time is added to the current simulation time (simt). If negative, it adjusts the time-step by either adding or subtracting twice the quantum size based on the direction of change. If the derivative is zero, indicating no change, the event time is set to infinity. Lastly, if the computed time is in the past, the function resets it to a far future time to prevent any premature events. This ensures that the system evolves smoothly and accurately.

In the second-order LIQSS method, the recomputeNextTime function calculates the next event time by considering both the state (x) and its first (x1) and second (x2) derivatives, along with the quantized state (q). The function constructs a polynomial using the current state, derivative values, and the second derivative, then calculates the next event time by finding the smallest positive root of this polynomial.

computeNextInputTime: The computeNextInputTime functions focus on computing the next action when derivatives depend only on time. They assess changes in the derivatives over a specified elapsed time to compute the time increment until the next input action. If the derivatives are null, the function reverts to handling the system in a lower-order thus simplifying the calculation.

computeNextEventTime: The computeNextEventTime function calculates the next event time based on the zero-crossing function ($ZCFun$) of a system. It first checks if a sign change has occurred in the zero-crossing function, indicating that the system is leaving zero and should be considered an event, provided the previous value is significantly different from zero (to prevent duplicate events). If a sign change is detected, the function updates the event time to the current simulation time. If both the old and new values of the zero-crossing function are zero, it sets the next event time to infinity, indicating no event should occur. For cases where the old and new values have the same sign, it calculates the minimum positive root of the zero-crossing function, representing the time of the next event, ensuring that this time is not too close to zero to avoid spurious events. The function then updates the old sign values for future comparisons.

Quantizer references

QuantizedSystemSolver.integrateStateMethod
integrateState(::Val{0}, x::Taylor0, elapsed::Float64)

does nothing: created for elapse-updating q in order1 which does not happen. This is needed in order to have one integrator function for all orders.

source
QuantizedSystemSolver.integrateStateMethod
integrateState(::Val{1}, x::Taylor0, elapsed::Float64)

Integrates the state for a first-order quantized system.

Arguments

  • ::Val{1}: A type parameter indicating the order of the quantized system.
  • x::Taylor0: The current state variable x represented as a Taylor0 object.
  • elapsed::Float64: The elapsed time since the last integration step of this variable x.
source
QuantizedSystemSolver.integrateStateMethod
integrateState(::Val{2}, x::Taylor0, elapsed::Float64)

Integrates a state variable x and its first derivative using a second-order Taylor series approximation

Arguments

  • ::Val{2}: A type parameter indicating the order of the Taylor series (second-order in this case).
  • x::Taylor0: The current state variable x represented as a Taylor0 object.
  • elapsed::Float64: The elapsed time over which to integrate the state x.
source
QuantizedSystemSolver.computeDerivativeMethod
computeDerivative(::Val{1}, x::Taylor0, f::Taylor0)

copies the derivative from f to the first derivative of x for the first order.

Arguments

  • ::Val{1}: A type parameter indicating the order of the derivative.
  • x::Taylor0: The state variable .
  • f::Taylor0: The Taylor series function that corresponds to the derivative.
source
QuantizedSystemSolver.computeDerivativeMethod
computeDerivative(::Val{2}, x::Taylor0, f::Taylor0)

copies the first and second derivatives from f to the derivatives of x for the second-order quantizer.

Arguments

  • ::Val{2}: A type parameter indicating the order of the quantizer.
  • x::Taylor0: The state variable .
  • f::Taylor0: The Taylor series function that corresponds to the derivative.
source
QuantizedSystemSolver.computeNextTimeMethod
computeNextTime(::Val{1}, i::Int, simt::Float64, nextTime::Vector{Float64}, x::Vector{Taylor0}, quantum::Vector{Float64})

Compute the next time of change for a given state variable.

Arguments

  • ::Val{1}: A type parameter indicating a first order quantization method.
  • i::Int: The index of the current state variable.
  • simt::Float64: The current simulation time.
  • nextTime::Vector{Float64}: A vector containing the next time values for each state variable.
  • x::Vector{Taylor0}: A vector of Taylor series coefficients representing the state variables and their derivatives.
  • quantum::Vector{Float64}: A vector containing the quantum values for the state variables.

Returns

  • The function updates the nextTime vector with the computed next time values for the state variables.
source
QuantizedSystemSolver.computeNextTimeMethod
computeNextTime(::Val{2}, i::Int, simt::Float64, nextTime::Vector{Float64}, x::Vector{Taylor0}, quantum::Vector{Float64})

Compute the next time for a given state variable i in a second-order quantized system.

Arguments

  • ::Val{2}: A type parameter indicating the order of the quantized system (second-order).
  • i::Int: The index of variable for which the next time is being computed.
  • simt::Float64: The current simulation time.
  • nextTime::Vector{Float64}: A vector containing the next times for all variables.
  • x::Vector{Taylor0}: A vector of Taylor series coefficients representing the state variables and their derivatives.
  • quantum::Vector{Float64}: A vector of quantum values for the state variables.

Returns

  • Nothing: This function updates the nextTime vector in place.
source
QuantizedSystemSolver.reComputeNextTimeMethod
reComputeNextTime(::Val{1}, index::Int, simt::Float64, nextTime::Vector{Float64}, x::Vector{Taylor0}, q::Vector{Taylor0}, quantum::Vector{Float64})

Recomputes the next time for a given state variable i in a first-order quantized system after the derivative has changed. similar to computeNextTime but it also account for the first derivative change.

source
QuantizedSystemSolver.reComputeNextTimeMethod
reComputeNextTime(::Val{2}, index::Int, simt::Float64, nextTime::Vector{Float64}, x::Vector{Taylor0}, q::Vector{Taylor0}, quantum::Vector{Float64})

Recomputes the next time for a given state variable i in a second-order quantized system after the derivatives have changed. similar to computeNextTime but it also account for the first and second derivatives changes.

source
QuantizedSystemSolver.computeNextInputTimeMethod
computeNextInputTime(::Val{1}, i::Int, simt::Float64, elapsed::Float64, tt::Taylor0, nextInputTime::Vector{Float64}, x::Vector{Taylor0}, quantum::Vector{Float64})

Compute the next input time for a given state variable in a first order method. This is needed when the differential equation depends on time only (i.e. does not depend on other state variables). It uses a prediction of the derivatives.

Arguments

  • ::Val{1}: A type parameter indicating the specific method to use.
  • i::Int: The index of the current state variable.
  • simt::Float64: The current simulation time.
  • elapsed::Float64: The elapsed time since the last update.
  • tt::Taylor0: The Taylor series expansion of the state variable in a small time advance.
  • nextInputTime::Vector{Float64}: A vector to store the computed next input times.
  • x::Vector{Taylor0}: A vector of Taylor series expansions of the state variables.
  • quantum::Vector{Float64}: A vector of quantum values for the state variables.

Returns

  • Nothing, it updates the nextInputTime vector with the next input times for the state variables.
source
QuantizedSystemSolver.computeNextInputTimeMethod
computeNextInputTime(::Val{2}, i::Int, simt::Float64, elapsed::Float64, tt::Taylor0, nextInputTime::Vector{Float64}, x::Vector{Taylor0}, quantum::Vector{Float64})

Compute the next input time for a given state variable in a second order method. This is needed when the differential equation depends on time only (i.e. does not depend on other state variables). It uses a prediction of the derivatives.

source
QuantizedSystemSolver.computeNextEventTimeMethod
computeNextEventTime(::Val{O},j::Int,ZCFun::Taylor0,oldsignValue::MMatrix{Z,2} ,simt::Float64,  nextEventTime :: MVector{Z,Float64}, quantum::Vector{Float64},absQ::Float64) where {O, Z}

Compute the next event time for a given zero-crossing function.

Arguments

  • ::Val{O}: A type parameter indicating the order of the quantizer.
  • j::Int: The index of the zero-crossing function being processed.
  • ZCFun::Taylor0: the value of the zero-crossing function of type Taylor0.
  • oldsignValue::MMatrix{Z,2}: The previous sign and value of the zero-crossing function.
  • simt::Float64: The current simulation time.
  • nextEventTime:: MVector{Z,Float64}: Vector contains the next event time for all zero-crossing functions.
  • quantum::Vector{Float64}: A vector of quantum values for the state variables.
  • absQ::Float64: The absolute quantum value.

Returns

  • The computed next event time for the state variable j.
source
QuantizedSystemSolver.updateQMethod
updateQ(::Val{1}, i::Int, xv::Vector{Taylor0}, qv::Vector{Taylor0}, quantum::Vector{Float64}, exactA::Function, d::Vector{Float64}, cacheA::MVector{1,Float64}, dxaux::Vector{MVector{1,Float64}}, qaux::Vector{MVector{1,Float64}}, tx::Vector{Float64}, tq::Vector{Float64}, simt::Float64, ft::Float64, nextStateTime::Vector{Float64},f::F) where{F}

Update the quantized state for the LIQSS1 (Linearly Implicit Quantized State System 1) method.

Arguments

  • ::Val{1}: Type parameter indicating the LIQSS1 method.
  • i::Int: Index of the state variable to update.
  • xv::Vector{Taylor0}: Vector of current state values.
  • qv::Vector{Taylor0}: Vector of quantized state values.
  • quantum::Vector{Float64}: Vector of quantum values for the state variables.
  • exactA::Function: Function to compute the exact value of a jacobian entry.
  • d::Vector{Float64}: Vector of discrete variables.
  • cacheA::MVector{1,Float64}: Cache for jacobian entry computation.
  • dxaux::Vector{MVector{1,Float64}}: Auxiliary vector for saving old x values.
  • qaux::Vector{MVector{1,Float64}}: Auxiliary vector for saving old quantized values.
  • tx::Vector{Float64}: Vector of times at which the state variables were updated.
  • tq::Vector{Float64}: Vector of times at which the quantized state variables were updated.
  • simt::Float64: Current simulation time.
  • ft::Float64: Final time of the simulation.
  • nextStateTime::Vector{Float64}: Vector of times at which the state variables will be updated next.

Returns

  • None. The function updates the quantized state and other info in place.
source
QuantizedSystemSolver.updateQInitMethod
updateQInit(::Val{1}, i::Int, xv::Vector{Taylor0}, qv::Vector{Taylor0}, quantum::Vector{Float64}, exactA::Function, d::Vector{Float64}, cacheA::MVector{1,Float64}, dxaux::Vector{MVector{1,Float64}}, qaux::Vector{MVector{1,Float64}}, tx::Vector{Float64}, tq::Vector{Float64}, simt::Float64, ft::Float64, nextStateTime::Vector{Float64},f::F) where{F}

Initialize the quantized state for the LIQSS1 method.

Arguments

  • ::Val{1}: Type parameter indicating the LIQSS1 method.
  • i::Int: Index of the state variable to update.
  • xv::Vector{Taylor0}: Vector of state variables.
  • qv::Vector{Taylor0}: Vector of quantized state variables.
  • quantum::Vector{Float64}: Vector of quantum values for the state variables.
  • exactA::Function: Function to compute the exact value of the state variable.
  • d::Vector{Float64}: Vector of derivatives of the state variables.
  • cacheA::MVector{1,Float64}: Cache for intermediate computations.
  • dxaux::Vector{MVector{1,Float64}}: Auxiliary vector for derivatives.
  • qaux::Vector{MVector{1,Float64}}: Auxiliary vector for quantized states.
  • tx::Vector{Float64}: Vector of times at which state variables were last updated.
  • tq::Vector{Float64}: Vector of times at which quantized state variables were last updated.
  • simt::Float64: Current simulation time.
  • ft::Float64: Final simulation time.
  • nextStateTime::Vector{Float64}: Vector of times at which the next state update is scheduled.

Description

This function initializes the quantized state for the LIQSS1 method by updating the quantized state variables and their associated times based on the provided state variables, derivatives, and quantum values.

source
QuantizedSystemSolver.Liqss_reComputeNextTimeMethod
Liqss_reComputeNextTime(::Val{1}, i::Int, simt::Float64, nextStateTime::Vector{Float64}, xv::Vector{Taylor0}, qv::Vector{Taylor0}, quantum::Vector{Float64})

Recomputes the next time for the LIQSS1 quantizer.

Arguments

  • ::Val{1}: Type parameter indicating the LIQSS1 method.
  • i::Int: Index of the state variable.
  • simt::Float64: Current simulation time.
  • nextStateTime::Vector{Float64}: Vector containing the next state times for each state variable.
  • xv::Vector{Taylor0}: Vector of current state values represented as Taylor series.
  • qv::Vector{Taylor0}: Vector of quantized state values represented as Taylor series.
  • quantum::Vector{Float64}: Vector of quantum values for the state variables.

Returns

  • Updates the nextStateTime vector with the recomputed next time for the specified state variable.
source
QuantizedSystemSolver.nmisCycle_and_simulUpdateMethod
nmisCycle_and_simulUpdate(aij::Float64,aji::Float64,trackSimul,::Val{1},Val(M),index::Int,j::Int,dirI::Float64, x::Vector{Taylor0},q::Vector{Taylor0}, quantum::Vector{Float64},exactA::Function,d::Vector{Float64},cacheA::MVector{1,Float64},dxaux::Vector{MVector{1,Float64}},qaux::Vector{MVector{1,Float64}},tx::Vector{Float64},tq::Vector{Float64},simt::Float64,ft::Float64,f::F) where {M,F}

Performs a simultaneous update of two quantized variables qi and qj if cycle conditions are met.

Arguments

  • aij::Float64: linear approximation Coefficient for the jacobian entry between variable i and variable j.
  • aji::Float64: linear approximation Coefficient for the jacobian entry between variable j and variable i.
  • trackSimul: A tracking object for the simulataneous update.
  • ::Val{1}: A type parameter indicating the method order is order 1.
  • ::Val{M}: A type parameter indicating the detection mechanism.
  • index::Int: The index of the current variable.
  • j::Int: The index of the interacting variable.
  • dirI::Float64: Direction of variable i.
  • x::Vector{Taylor0}: State vector of Taylor series coefficients for the variables.
  • q::Vector{Taylor0}: Quantized state vector of Taylor series coefficients for the variables.
  • quantum::Vector{Float64}: Quantum levels for the variables.
  • exactA::Function: Function to compute the exact value of a jacobian entry.
  • d::Vector{Float64}: discrete variables.
  • cacheA::MVector{1,Float64}: Cache for jacobian entry computation.
  • dxaux::Vector{MVector{1,Float64}}: Auxiliary vector for old x values.
  • qaux::Vector{MVector{1,Float64}}: Auxiliary vector for old quantized values.
  • tx::Vector{Float64}: Time vector for state updates.
  • tq::Vector{Float64}: Time vector for quantized state updates.
  • simt::Float64: Current simulation time.
  • ft::Float64: Final time for the simulation.

Returns

  • None. The function performs in-place updates on the quantized state vectors.
source
QuantizedSystemSolver.updateQMethod
updateQ(::Val{2}, i::Int, xv::Vector{Taylor0}, qv::Vector{Taylor0}, quantum::Vector{Float64}, exactA::Function, d::Vector{Float64}, cacheA::MVector{1,Float64}, dxaux::Vector{MVector{2,Float64}}, qaux::Vector{MVector{2,Float64}}, tx::Vector{Float64}, tq::Vector{Float64}, simt::Float64, ft::Float64, nextStateTime::Vector{Float64},f::F) where{F}

Update the quantized state for the second-order quantizer.

Arguments

  • ::Val{2}: Type parameter indicating the second-order quantizer.
  • i::Int: Index of the state variable to update.
  • xv::Vector{Taylor0}: Vector of state variables.
  • qv::Vector{Taylor0}: Vector of quantized state variables.
  • quantum::Vector{Float64}: Vector of quantum values of the state variables.
  • exactA::Function: Function to compute the exact value of a jacobian entry.
  • d::Vector{Float64}: Vector of discrete variables.
  • cacheA::MVector{1,Float64}: Cache for jacobian entry computation.
  • dxaux::Vector{MVector{2,Float64}}: Auxiliary vector for saving old x values.
  • qaux::Vector{MVector{2,Float64}}: Auxiliary vector for saving old quantized values.
  • tx::Vector{Float64}: Vector of state update times.
  • tq::Vector{Float64}: Vector of quantized state update times.
  • simt::Float64: Current simulation time.
  • ft::Float64: Final time of the simulation.
  • nextStateTime::Vector{Float64}: Vector of times for the next state updates.
source
QuantizedSystemSolver.updateQInitMethod
updateQInit(::Val{2}, i::Int, xv::Vector{Taylor0}, qv::Vector{Taylor0}, quantum::Vector{Float64}, exactA::Function, d::Vector{Float64}, cacheA::MVector{1,Float64}, dxaux::Vector{MVector{2,Float64}}, qaux::Vector{MVector{2,Float64}}, tx::Vector{Float64}, tq::Vector{Float64}, simt::Float64, ft::Float64, nextStateTime::Vector{Float64},f::F) where{F}

Initialize the quantized state variables for the LIQSS2 method. It is similar to the updateQ function but does not accept q to be set to x when all derivatives are zero, which is the case when an equilibrium ocurrs during the simulation.

source
QuantizedSystemSolver.Liqss_reComputeNextTimeMethod
Liqss_reComputeNextTime(::Val{2}, i::Int, simt::Float64, nextStateTime::Vector{Float64}, xv::Vector{Taylor0}, qv::Vector{Taylor0}, quantum::Vector{Float64})

Recomputes the next time for a given state in a second-order quantized state system.

Arguments

  • ::Val{2}: A type parameter indicating the order of the quantized state system (second-order in this case).
  • i::Int: The index of the state for which the next time is being recomputed.
  • simt::Float64: The current simulation time.
  • nextStateTime::Vector{Float64}: A vector containing the next state times for all states.
  • xv::Vector{Taylor0}: A vector containing the current state values represented as Taylor series.
  • qv::Vector{Taylor0}: A vector containing the quantized state values represented as Taylor series.
  • quantum::Vector{Float64}: A vector containing the quantum values the states.

Returns

  • This function does not return a value. It updates the nextStateTime vector in place.
source
QuantizedSystemSolver.nmisCycle_and_simulUpdateMethod
nmisCycle_and_simulUpdate(aij::Float64,aji::Float64,trackSimul,::Val{2},Val(M),index::Int,j::Int,dirI::Float64, x::Vector{Taylor0},q::Vector{Taylor0}, quantum::Vector{Float64},exactA::Function,d::Vector{Float64},cacheA::MVector{1,Float64},dxaux::Vector{MVector{2,Float64}},qaux::Vector{MVector{2,Float64}},tx::Vector{Float64},tq::Vector{Float64},simt::Float64,ft::Float64,f::F) where {M,F}

Performs a simultaneous update of two quantized variables qi and qj and their derivatives if cycle conditions are met. This is similar to the nmisCycle_and_simulUpdate order 1 function.

source

Index