Direct-Switch: High-Order Discretization Method
- Direct-Switch is a computational framework that reformulates nonsmooth differential equations as a dynamic complementarity system with exact switch detection.
- It integrates variable step Runge–Kutta schemes with cross-complementarity and step equilibration to force switching events onto mesh boundaries and recover high-order accuracy.
- The method streamlines nonsmooth optimal control by transcribing the problem into a single MPCC, eliminating the need for pre-guessing switching sequences and improving sensitivity analysis.
Direct-Switch, also described as Finite Elements with Switch Detection (FESD), is a direct-optimal-control and numerical discretization methodology for nonsmooth differential equations in which switching events are detected exactly by making the integrator step sizes degrees of freedom and by adding complementarity conditions that force every switch onto a mesh boundary. In the formulation developed for piecewise-smooth ODEs and later extended to systems with set-valued step functions, the original nonsmooth dynamics are first rewritten as a dynamic complementarity system (DCS), then discretized by a Runge–Kutta scheme whose step sizes are allowed to vary, and finally transcribed into a single Mathematical Program with Complementarity Constraints (MPCC). The central purpose of the method is to recover the high-order accuracy and sensitivity information that standard fixed-step Runge–Kutta methods lose on nonsmooth trajectories (Nurkanović et al., 2022, Nurkanović et al., 2023).
1. Problem class and motivating setting
Direct-Switch addresses nonsmooth dynamical systems whose right-hand side changes across regions of the state space. In the piecewise-smooth setting, the initial-value problem is written as
where the regions are disjoint open regions with smooth boundaries, and each is smooth on a neighborhood of . Filippov’s construction replaces the discontinuous right-hand side by a set-valued map and yields a convexified dynamics
with measurable Filippov multipliers , , and whenever (Nurkanović et al., 2022).
The 2023 extension generalizes the same program to optimal control problems with set-valued step functions. On a horizon , the dynamics are posed as
0
with switching functions 1 and
2
The paper states that such differential inclusions subsume Filippov systems, piecewise-smooth ODEs, and many hybrid-logic expressions (Nurkanović et al., 2023).
A recurring motivation is that naive discretization is structurally inadequate. The 2022 paper states that if standard time-stepping Runge–Kutta methods are naively applied to a nonsmooth ODE, the accuracy is at best of order one, and the 2023 extension makes the same point for DCS models with set-valued step functions, where only 3 global order is observed regardless of the base Runge–Kutta order (Nurkanović et al., 2022, Nurkanović et al., 2023). This is the methodological gap Direct-Switch is designed to close.
2. Complementarity reformulation of switching logic
A defining feature of Direct-Switch is that it does not work directly with a discontinuous right-hand side. Instead, it rewrites switching logic as algebraic complementarity constraints.
For piecewise-smooth ODEs, the formulation follows Stewart’s dynamic-complementarity system. With 4, smooth indicator functions 5, and auxiliary variables 6, the DCS is
7
The paper presents this as the KKT reformulation of the linear program
8
which encodes the active region selection in complementarity form (Nurkanović et al., 2022).
For set-valued step functions, the reformulation is different in detail but identical in spirit. Each step variable 9 is written as the solution of a small LP,
0
whose KKT conditions introduce dual variables 1: 2 The paper states explicitly that this reproduces the set-valued step-function exactly: if 3 then 4, if 5 then 6, and if 7 then 8 (Nurkanović et al., 2023).
When the nonsmooth ODE can be expressed as a convex combination over sign-defined regions,
9
the extension constructs Filippov multipliers
0
with 1 encoding the sign patterns. This yields a DCS in which 2 are algebraic complementarity variables that encode exactly the switching logic of the original set-valued step (Nurkanović et al., 2023).
3. FESD discretization and exact switch detection
The distinctive step of Direct-Switch is the FESD discretization itself. Standard 3-stage Runge–Kutta discretization with fixed step sizes 4 does not detect the exact switch time unless it happens to coincide with a mesh point. FESD therefore promotes each 5 to a decision variable and imposes
6
This introduces new degrees of freedom, which are then pinned down by two additional families of conditions: cross-complementarity and step equilibration (Nurkanović et al., 2022).
In the original formulation, the stage variables on 7 are 8, together with 9. The paper’s key algebraic condition is
0
including boundary stages. Compacted over an interval, this becomes 1. Lemma 3.1 shows that these pairwise products force a single invariant active set on each interval, so an active-set change cannot occur in the interior of a finite element. Any switch is therefore forced onto a mesh boundary (Nurkanović et al., 2022).
The 2023 step-function extension uses an analogous mechanism. Because the LP multipliers 2 are continuous in continuous time and both must vanish at a zero crossing of 3, it imposes for each interval and every pair of distinct stage indices 4 the cross-complementarity conditions
5
The paper states that this prevents an active-set change from hiding between Runge–Kutta stages and forces the designer to align that switch exactly with a mesh point (Nurkanović et al., 2023).
Cross-complementarity alone is insufficient, because if no switch occurs on 6, then the free variables 7 would remain underdetermined. Step equilibration removes this spurious freedom. In the 2022 formulation, one defines an indicator 8 such that 9 if and only if no switch occurs at 0, and imposes
1
Hence 2 whenever no switch occurs, while the condition becomes vacuous at a true switch (Nurkanović et al., 2022). The 2023 extension gives the same principle in the form
3
with 4 if and only if no switch occurs on 5 (Nurkanović et al., 2023).
A common misconception is that high-order Runge–Kutta formulas alone suffice for nonsmooth systems. The Direct-Switch construction is explicitly built on the opposite conclusion: without exact switch detection, one loses high-order accuracy; with free step sizes, cross-complementarity, and step equilibration, the scheme recovers it (Nurkanović et al., 2022, Nurkanović et al., 2023).
4. Direct transcription into an MPCC
Once discretized, Direct-Switch transcribes the entire nonsmooth optimal-control problem into one large MPCC rather than into a sequence of event-detection subproblems.
For the step-function extension, the finite-element Runge–Kutta equations on one interval are written with stage variables 6: 7 together with the DCS constraints at each stage. Collecting all state and algebraic variables over all finite elements plus the vector of step sizes yields a single large system consisting of state updates, stage equations, complementarity conditions, cross-complementarity conditions, step-equilibration conditions, and the horizon constraint 8. The paper identifies this explicitly as an MPCC (Nurkanović et al., 2023).
The direct transcription of the optimal-control problem proceeds by dividing 9 into 0 control intervals with piecewise-constant controls 1, applying FESD with 2 finite elements on each interval, and minimizing a discrete objective
3
subject to the FESD-discretized DCS equations, path constraints, terminal constraints, and sum-of-steps constraints (Nurkanović et al., 2023).
The 2022 paper gives the same overall architecture in the piecewise-smooth setting and emphasizes that the framework is a direct-optimal-control method that no longer needs pre-guessing or enumeration of switching sequences (Nurkanović et al., 2022). The 2023 extension adds implementation details: in NOSNOC, each complementarity 4 is replaced by a smooth C-function such as Fischer–Burmeister, a decreasing sequence of smoothing parameters drives the solution toward the true MPCC, and the underlying smooth NLPs are solved by IPOPT via CasADi (Nurkanović et al., 2023).
5. Accuracy, convergence, and numerical sensitivities
The formal analysis of Direct-Switch is one of its central features. Under assumptions including invertibility of certain matrices off-switch, strict complementarity, strong stability of the switching LCP, and a convergent Runge–Kutta method of order 5, the 2022 paper proves that the FESD-discrete system has locally isolated solutions for each fixed switching pattern and that FESD trajectories converge to a true Filippov solution with order 6 away from switches and order 7 at switches (Nurkanović et al., 2022).
The quoted error bounds include both event time and state accuracy: 8 at every mesh point, including those that coincide with switching times. The same paper also states that the discrete-time sensitivities 9 converge to the correct Filippov sensitivity jumps with order 0, often 1 for stiffly accurate Runge–Kutta methods (Nurkanović et al., 2022).
The extension to set-valued step functions frames the same numerical issue in sharper terms. If a standard 2-stage Runge–Kutta method with fixed step sizes is applied directly to the DCS, only 3 global order is observed, no matter how high the Runge–Kutta order. By contrast, the paper reports that FESD with an underlying Radau IIA method of order 4 recovers global 5 in a planar oscillator example with one crossing at 6 (Nurkanović et al., 2023).
The corresponding methodological significance is precise: Direct-Switch does not merely refine the mesh near nonsmoothness; it enforces an exact alignment of switches with finite-element boundaries, and the recovery of high-order accuracy follows from that alignment together with the underlying Runge–Kutta order (Nurkanović et al., 2022, Nurkanović et al., 2023).
6. Benchmarks, software realization, and scope
The published benchmarks emphasize both solution quality and computational behavior. In the 2022 optimal-control benchmark
7
standard fixed-step Gauss–Legendre or Radau discretization yields an objective curve 8 with spurious local minima and incorrect gradients, whereas FESD recovers the exact objective curve, correct derivatives, and a single global minimum. In a switched-oscillator–MPC benchmark, FESD achieves five orders of magnitude smaller terminal error versus CPU time than the standard fixed-step approach, and the abstract summarizes this as up to five orders of magnitude more accurate solutions for the same computational time (Nurkanović et al., 2022).
The 2023 paper reports complementary evidence in a different model class. For a planar oscillator, classical Runge–Kutta time stepping of the DCS remains first-order, while FESD with Radau IIA recovers the base order. For an optimal control problem of a hopping robot, where leg-tip impact and frictional-sliding logic are expressed as three step-functions in normal and tangential velocity, a Radau-IIA(3)-based FESD directly discretizes the task of making five jumps in five seconds. In CPU-timing studies over increasing numbers of control intervals, FESD via the step-LP reformulation is up to 50% faster per NLP iteration than the earlier Stewart-based DCS reformulation because it uses fewer auxiliary variables and sparser complementarity (Nurkanović et al., 2023).
NOSNOC is the software package explicitly associated with the method in the step-function extension, and all methods and examples in that paper are implemented there (Nurkanović et al., 2023). A plausible implication is that Direct-Switch has evolved from a numerical discretization strategy into a software-supported direct-transcription framework for nonsmooth optimal control.
Within its documented scope, Direct-Switch is characterized by four recurring properties: it rewrites switching logic as complementarity constraints, lets mesh steps float, enforces exact switch detection through cross-complementarity, and uses step equilibration to prevent nonphysical mesh drift. The resulting framework is presented as provably high-order accurate, sensitivity-consistent, and applicable without pre-guessing or enumeration of switching sequences (Nurkanović et al., 2022, Nurkanović et al., 2023).