Skip to content
Specular Differentiation

specular.ode.ellipse_scheme

ellipse_scheme(F, t_0, T, u_0, *, h, sigma_n=None, third_order=False, fourth_order=False, auto=False, domain=None, admissible=None, derivatives_of_F=None, derivative_step=None, atol=1e-12, rtol=0.0, max_iter=100)

Solve a scalar initial-value problem on [t_0, T] with the implicit specular ellipse method.

Parameters

Name Type and default Description
F callable Field F(point) receiving a NumPy float64 vector point = [t, u] of shape (2,) and returning a finite real scalar.
t_0 real scalar Finite initial time.
T real scalar Finite final time, strictly greater than t_0.
u_0 real scalar Finite initial value at t_0.
h positive real scalar, keyword-only Prescribed constant step, with 0 < h <= T - t_0. The number of steps is N_h = floor((T - t_0)/h).
sigma_n positive real scalar or callable, default None Required in the base mode. A callable sigma_n(n, t_n, u_n, h) returns a finite positive scale and is evaluated once at the accepted left endpoint. Its fourth argument is the prescribed constant h. Must be None in an automatic mode.
third_order bool, default False Use the SE3 scale when 0 < beta_n*a_n < 3*p_n, and 1.0 otherwise; freeze it during each step.
fourth_order bool, default False Use the SE4 scale only when both endpoint conditions and A*C < 0 hold; use 1.0 otherwise.
auto bool, default False Prefer SE4, then the left-endpoint SE3 scale, then 1.0, reevaluating the checks at every trial value.
derivatives_of_F callable or None, default None In an automatic mode, optionally map the NumPy array [t, u] to [D_F F, D_F^2 F], also of shape (2,). Omit to estimate these derivatives numerically.
derivative_step positive real scalar or None, default None Finite-difference step for automatic modes. Cannot be combined with derivatives_of_F.
atol real scalar, default 1e-12 Finite positive absolute tolerance zeta; accept only when abs(v_next - v) < atol.
rtol real scalar, default 0.0 Compatibility parameter; must be zero because the algorithm uses an absolute tolerance.
max_iter positive integer, default 100 Maximum number of fixed-point updates per step; failure raises RuntimeError.
domain callable or None, default None Boolean predicate domain(t, u) for the field domain, checked before every field evaluation.
admissible callable or None, default None Boolean predicate admissible(t_next, v) for trial states, checked before and after each update.

All parameters after u_0 are keyword-only. The three automatic-mode flags are mutually exclusive. Derivative controls are valid only in an automatic mode. Here \(D_F=\partial_t+F\partial_u\) denotes differentiation along solution curves.

Returns

ODEResult: NumPy float64 arrays t and u of shape (N_h + 1,), a scale array sigma of shape (N_h,), and the number of solver calls to F. The arrays t and u are views of separate rows of one preallocated grid. The nodes are t_0 + n*h; the final node may precede T because no shortened last step is added.

Notes

For a prescribed scale, the update is

\[ u_{n+1}=u_n+h\mathcal C_{\sigma_n}\!\left( F(t_{n+1},u_{n+1}),F(t_n,u_n)\right). \]

The scale is frozen during each implicit solve. Angular means use the selected calculation backend; the outer iteration uses Python floats and NumPy float64 arrays. See Prescribed scale.

The fixed-point iteration starts from the Euler predictor and returns the updated trial value when the strict absolute stopping condition holds. There is no bracket search or alternative predictor. Local convergence is conditional. A failed solve raises RuntimeError; a smaller time step may help. Exceptions from F are preserved. See Nonlinear solve controls.

The order flags do not guarantee their named order for arbitrary fields. Third-order convergence requires a sufficiently smooth, bounded selected branch and accurate derivatives. The fourth-order theorem additionally requires the stated solution-tube hypotheses, including elliptic malleability and nondegeneracy; steps using a fallback scale do not inherit that guarantee. The auto option permits an SE3 fallback and does not provide an unconditional fourth-order guarantee. See Automatic scale-selection modes.

Numerical derivative estimation may sample F outside [t_0, T]; the field must be defined on a neighborhood of the interval, or exact derivatives must be supplied. Rapid variation can require an explicit derivative_step or an accurate derivative callback. All recorded scales are finite and positive.

Examples

import specular.ode

result = specular.ode.ellipse_scheme(
    lambda point: -point[1],
    0.0,
    1.0,
    1.0,
    h=0.01,
    sigma_n=1.0,
)
print(result.t[-1], result.u[-1])
Source code in specular/ode/solver.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def ellipse_scheme(
    F: VectorToScalarFunc,
    t_0: Scalar,
    T: Scalar,
    u_0: Scalar,
    *,
    h: Scalar,
    sigma_n: Scalar | StepScale | None = None,
    third_order: bool = False,
    fourth_order: bool = False,
    auto: bool = False,
    domain: Callable[[float, float], bool] | None = None,
    admissible: Callable[[float, float], bool] | None = None,
    derivatives_of_F: VectorToVectorFunc | None = None,
    derivative_step: Scalar | None = None,
    atol: Scalar = 1e-12,
    rtol: Scalar = 0.0,
    max_iter: int = 100,
) -> ODEResult:
    r"""Apply the scalar specular ellipse method with prescribed step ``h``.

    ``F`` accepts a NumPy vector ``[t, u]`` and returns a real scalar.
    The solver allocates the mesh ``t_n = t_0 + n*h`` for
    ``n = 0, ..., floor((T-t_0)/h)`` and its solution row before passing
    them to the method. No shortened final step is added.

    In the base mode, ``sigma_n`` is a positive scalar or a callable
    ``sigma_n(n, t_n, u_n, h)`` and is frozen during its implicit step.
    The fourth argument is the same prescribed ``h`` at every step.
    ``third_order=True`` uses the SE3 scale when its left-endpoint guard
    holds and scale ``1.0`` otherwise. ``fourth_order=True`` uses SE4's
    two endpoint guards and ``A*C < 0``, with scale ``1.0`` otherwise.
    ``auto=True`` first attempts SE4 and uses the SE3 scale as fallback.
    The three automatic modes are mutually exclusive.

    When ``derivatives_of_F`` is omitted, ``D_F F`` and ``D_F^2 F`` are
    estimated from ``F`` along a local RK4 flow. Otherwise the callback
    maps ``[t, u]`` to ``[D_F F, D_F^2 F]``.

    Each step uses the Euler predictor and at most ``max_iter`` fixed-point
    updates, accepting the new iterate when its absolute change is strictly
    below ``atol``. ``rtol`` must be zero. ``domain(t, u)`` tests membership
    in Omega; ``admissible(t, v)`` tests membership in the trial set V at the
    next time. Omitted predicates admit all finite points, subject to the
    supplied domain. Both the input and output of each map evaluation must
    be admissible. ``result.sigma`` records the scale used in the last map
    evaluation of each accepted step.
    """

    h = float(h)
    grid = _initialize_grid(t_0, T, h, u_0)
    return _ellipse.ellipse_scheme(
        F, grid, h=h, sigma_n=sigma_n,
        third_order=third_order, fourth_order=fourth_order,
        auto=auto,
        domain=domain, admissible=admissible,
        derivatives_of_F=derivatives_of_F, derivative_step=derivative_step,
        atol=atol, rtol=rtol, max_iter=max_iter,
    )