diff --git a/joss.07434/paper.jats/10.21105.joss.07434.jats b/joss.07434/paper.jats/10.21105.joss.07434.jats new file mode 100644 index 000000000..72347c9de --- /dev/null +++ b/joss.07434/paper.jats/10.21105.joss.07434.jats @@ -0,0 +1,472 @@ + + +
+ + + + +Journal of Open Source Software +JOSS + +2475-9066 + +Open Journals + + + +7434 +10.21105/joss.07434 + +QuantizedSystemSolver: A discontinuous ODE system solver +in Julia. + + + +https://orcid.org/0000-0003-1230-5488 + +Elbellili +Elmongi + + + + + +https://orcid.org/0000-0002-0536-2647 + +Huybrechs +Daan + + + + +https://orcid.org/0000-0003-0761-6265 + +Lauwens +Ben + + + + + +Royal Military Academy, Brussels, Belgium + + + + +KU Leuven, Leuven, Belgium + + + +10 +105 +7434 + +Authors of papers retain copyright and release the +work under a Creative Commons Attribution 4.0 International License (CC +BY 4.0) +2025 +The article authors + +Authors of papers retain copyright and release the work under +a Creative Commons Attribution 4.0 International License (CC BY +4.0) + + + +Quantised State System +Discontinuities +Stiff Ordinary Differential Equations + + + + + + Summary +

Contemporary engineering systems, such as electrical circuits, + mechanical systems with shocks, and chemical reactions with rapid + kinetics, are often characterized by dynamics that can be modeled + using stiff differential equations with events. Stiffness typically + arises in these systems due to the presence of both rapidly changing + and slowly changing components. This stiffness requires extremely + small time steps to maintain stability when using traditional + numerical integration techniques. Recently, quantization-based + techniques have emerged as an effective alternative for handling such + complex models. Methods like the Quantized State System (QSS) and the + Linearly Implicit Quantized State System (LIQSS) offer promising + results, particularly for large sparse stiff models. Unlike classic + numerical integration methods, which update all system variables at + each time step, the quantized approach updates individual system + variables independently. Specifically, in quantized methods, each + variable is updated only when its value changes by a predefined + quantization level. Moreover, these methods are advantageous when + dealing with discontinuous events. An event is a discontinuity where + the state of the system abruptly changes at a specific point. Classic + methods may struggle with events: They either undergo expensive + iterations to pinpoint the exact discontinuity instance or resort to + interpolating its location, resulting in unreliable outcomes. + Therefore, this QSS strategy can significantly reduce computational + effort and improve efficiency in large sparse stiff models with + frequent discontinuities + (Pietro + et al., 2019).

+
+ + Statement of need +

Traditional solvers are challenged by large sparse stiff models and + systems with frequent discontinuities. The buck converter is a stiff + system with frequent discontinuities that classic solvers from the + DifferentialEquations.jl + (Rackauckas + & Nie, 2017) are currently unable to handle properly. + Written in the easy-to-learn Julia programming language + (Bezanson + et al., 2017) and inspired by the + qss-solver written in C + (Fernández + & Kofman, 2014), the QuantizedSystemSolver.jl package takes + advantage of Julia features such as multiple dispatch and + metaprogramming. The package shares the same interface as the + DifferentialEquations.jl package and aims to efficiently solve a large + set of stiff Ordinary Differential Equations (ODEs) with events by + implementing the QSS and LIQSS methods. It is the first such tool to + be published in the Julia ecosystem.

+
+ + Quantization-based techniques +

The general form of a problem composed of a set of ODEs and a set + of events that QSS is able to solve is described in the following + equations:

+

+

where + + X=[x1,x2...,xn]T + is the state vector, + + f:n×m×+n + is the derivative function, and + + t + is the independent variable. + + P=[p1,p2...,pm]T + is the vector of the system discrete variables. + + + n + and + + m + are the number of state variables and discrete variables of the system + respectively. + + zc + is an event condition, + + H + and + + L + are functions used in the effects of the event + + + zc.

+

In QSS, besides the step size, the difference between + + + xi(tk) + (the current value) and + + xi(tk+1) + (the next value) is called the quantum + + Δi. + Depending on the type of the QSS method (explicit or implicit), a new + variable + + qi + is set to equal + + xi(tk) + or + + xi(tk+1) + respectively. + + qi + is called the quantized state of + + xi, + and it is used in updating the derivative function + (Elbellili + et al., 2024). A general description of a QSS algorithm is + given as follows: +

+
+ + Package description +

While the package is optimized to be fast, extensibility is not + compromised. It is divided into three entities that can be extended + separately: the problem, the + algorithm, and the + solution. The rest of the code creates these + entities and glues them together. The API was designed to match the + DifferentialEquations.jl interface while providing an easier way to + handle events. The problem is defined inside a function, in which the + user may introduce any parameters, variables, equations, and + events:

+ function func(du, u, p, t) + # parameters, helpers, differential eqs., if-statements for events; e.g.: + du[1] = p[1] * u[1] + if (t - 1.0 > 0.0) p[1] = -10.0 end +end +

Then, this function is passed to an + ODEProblem function along with the initial + conditions, the time span, and any parameters or discrete + variables.

+ tspan = (0.0, 2.0) +u = [10.0] # initial conditions +p = [-1.0] # parameters and discrete variables +odeprob = ODEProblem(func, u, tspan, p) +

The output of the previous ODEProblem + function, which is a QSS problem, is passed to a + solve function with other configuration + arguments such as the algorithm type and the tolerance. The + solve function dispatches on the given + algorithm and starts the numerical integration.

+ sol = solve(odeprob, nmliqss2(), abstol = 1E-5, reltol = 1E-5) +

At the end, a solution object is produced that can be queried, + plotted, and analyzed for error.

+ sol(0.05, idxs = 1) # get the value of variable 1 at time 0.05 +sol.stats # get statistics about the simulation +plot(sol) # plot the solution +

The solver uses other packages such as + MacroTools.jl + (Innes, + 2015) for user-code parsing and + SymEngine.jl + (Fernando, + 2015) for Jacobian computation and dependency extraction. It + also uses a modified + TaylorSeries.jl + (Benet + & Sanders, 2014) that implements caching to obtain free + Taylor variable operations, since the current version of TaylorSeries + creates a heap allocated object for every operation. The approximation + through Taylor variables transforms any complicated equations to + polynomials, making root finding cheaper–a process that QSS methods + rely on heavily.

+
+ + The buck converter example +

The buck converter decreases the voltage and increases the current + with a greater power efficiency than linear regulators + (Migoni + et al., 2015). Its circuit is shown in Fig.1(a).

+ +

The buck converter

+ +
+

The diode + + D + and the switch + + S + can be modeled as two variable resistors, denoted by + + + RD + and + + RS. + A mesh and a nodal analysis give the relationship between the + different components in the circuit as follows:

+

+ + id=RS.ilV1RS+RD; + + + ducdt=ilucRC; + + + dildt=ucid.RDL

+

The buck problem contains frequent discontinuities and can be + solved by the QuantizedSystemSolver.jl package using the following + code, that generates the solution plot of Fig.1(b):

+ using QuantizedSystemSolver +function buck(du, u, p, t) + # Constant parameters + C = 1e-4; L = 1e-4; R = 10.0; V1 = 24.0; T = 1e-4; ROn = 1e-5; ROff = 1e5 + # Optional rename of the continuous and discrete variables + RD = p[1]; RS = p[2]; nextT = p[3]; lastT = p[4]; il = u[1]; uc = u[2] + # Equations + id = (il * RS - V1) / (RD + RS) # diode's current + du[1] = (-id * RD - uc)/L; du[2] = (il - uc / R) / C + # Events + if t - nextT > 0.0 # model when the switch is ON + lastT = nextT; nextT = nextT + T; RS = ROn + end + if t - lastT - 0.5 * T > 0.0 # model when the switch is OFF + RS = ROff + end + if id > 0 # model when the Diode is ON + RD = ROn; + else + RD = ROff; + end +end +# Initial conditions and time settings +p = [1e5, 1e-5, 1e-4, 0.0]; u0 = [0.0, 0.0]; tspan = (0.0, 0.001) +# Define the problem +QSSproblem = ODEProblem(buck, u0, tspan, p) +# solve the problem +sol = solve(QSSproblem, nmliqss2(), abstol = 1e-3, reltol = 1e-2) +# Get the value of variable 2 at time 0.0005 +sol(0.0005, idxs = 2) +# plot the solution +plot(sol) +
+ + Conclusion +

The package provides robust functionality to efficiently solve + stiff ODEs with events using the quantized state method. It is + well-documented, making it accessible for researchers across various + domains. Additionally, users can extend its capabilities to handle a + variety of problems.

+
+ + Acknowledgements +

This research has received no external funding.

+
+ + + + + + + + BenetLuis + SandersDavid P. + + A Julia package for Taylor expansions in one or more independent variables + https://github.com/JuliaDiff/TaylorSeries.jl + 2014 + 10.5281/zenodo.2557003 + + + + + + BezansonJeff + EdelmanAlan + KarpinskiStefan + ShahViral B. + + Julia: A fresh approach to numerical computing + SIAM Review + 2017 + 59 + 1 + 10.1137/141000671 + 65 + 98 + + + + + + InnesMike + + MacroTools.jl + 2015 + https://github.com/FluxML/MacroTools.jl + + + + + + FernandoIsuru + + SymEngine.jl + 2015 + https://github.com/symengine/SymEngine.jl + + + + + + PietroF. + MigoniG. + KofmanE. + + Improving linearly implicit quantized state system methods + Simulation: Transactions of the Society for Modeling and Simulation International + 2019 + 10.1177/0037549718766689 + + + + + + FernándezJoaquín + KofmanErnesto + + A stand-alone quantized state system solver for continuous system simulation + SIMULATION: Transactions of the Society for Modeling and Simulation International + 201406 + 90 + 10.1177/0037549714536255 + 782 + 799 + + + + + + RackauckasC. + NieQ. + + DifferentialEquations.jl a performant and feature-rich ecosystem for solving differential equations in Julia + The Journal of Open Research Software + 2017 + 5 + 10.5334/jors.151 + 15 + 24 + + + + + + ElbelliliE. + LauwensB. + HuybrechsD. + + Investigation of different conditions to detect cycles in linearly implicit quantized state systems + Proceedings of the 3rd. International conference on computational modeling, simulation and optimization + IEEE Computer Society + 2024 + 10.1109/ICCMSO61761.2024.00095 + + + + + + MigoniGustavo + KofmanErnesto + BergeroFederico + FernandezJoaquin + + Quantization-based simulation of switched mode power supplies + SIMULATION + 201504 + 91 + 10.1177/0037549715575197 + 320 + 336 + + + + +