This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/ode/solve

One driver for every method of solving an initial value problem

ode_solve(rhs, jac, events, t0, t1, y0, p, cfg, t_eval, dirs, term) integrates y' = rhs(t, y, p) from t0 to t1 by the method cfg.method (DOPRI5, RADAU, BDF, or AUTO: Dormand-Prince until its stiffness test fires, then Radau IIA from that point). After each accepted step the driver

  • finds the events in it: a sign change of an entry of events(t, y, p) is located on the step's dense output to a few ulps; a terminal one ends the integration there;
  • writes the output: every step's endpoint, or the dense output at the requested times t_eval.

ode_batch runs one problem for many parameter vectors (the rows of P) and initial states, all on one output grid: the case that costs most when every solve is a separate call from Python.

What a problem must provide, and why. A def is passed as a function value, and the compiled engines specialize the integrator for it, so rhs, jac and events must be defs (or lambdas that read only their parameters and top-level names), not closures returned from a def. grad cannot follow a call through a function value, so an exact Jacobian is a def that names the rhs (see lib/ode/problems.viv: robertson_jac is three grads of robertson); pass jac_mode = JAC_FD to use forward differences instead. A problem with no events passes no_events and empty dirs.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

This program declares a record type (OdeResult), and records run only in compiled C for now, so the Run buttons here are off. Open it in the workbench and use its C tab to compile it.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 30–319