View Source Integrator.AdaptiveStepsize (Integrator v0.1.3)

Integrates a set of ODEs with an adaptive timestep.

Summary

Functions

Gets the default values used by the absolute-relative norm; e.g., abs_tol, rel_tol, and norm_control

Returns the total elapsed time for the integration (in milleseconds)

Computes a good initial timestep for an ODE solver of order order using the algorithm described in the reference below.

Types

@type event_fn_t() :: (Nx.t(), Nx.t() -> {integration_status(), Nx.t()})
@type integration_status() :: :halt | :continue
@type options_t() ::
  {:max_iterations, integer()}
  | {:max_fn_eval_count, integer()}
  | {:type, term()}
  | {:machine_eps, float()}
  | {:tolerance, float()}
  | {:nonlinear_eqn_root_output_fn, term()}
  | {:abs_tol, term()}
  | {:event_fn, (term(), term() -> term()) | nil}
  | {:max_number_of_errors, integer()}
  | {:max_step, term()}
  | {:norm_control, boolean()}
  | {:output_fn, (term(), term() -> term()) | nil}
  | {:refine, atom() | pos_integer()}
  | {:rel_tol, term()}
  | {:speed, atom() | float()}
  | {:store_results?, boolean()}
@type output_fn_t() :: ([Nx.t()], [Nx.t()] -> any())
@type refine_strategy() :: integer() | :fixed_times
@type speed() :: :no_delay | float()
@type t() :: %Integrator.AdaptiveStepsize{
  count_cycles__compute_step: integer(),
  count_loop__increment_step: integer(),
  dt: Nx.t() | nil,
  error_count: integer(),
  fixed_times: [Nx.t()] | nil,
  i_step: integer(),
  k_vals: Nx.t() | nil,
  nx_type: Nx.Type.t(),
  ode_t: [Nx.t()],
  ode_x: [Nx.t()],
  options_comp: Nx.t() | nil,
  output_t: [Nx.t()],
  output_x: [Nx.t()],
  t_new: Nx.t() | nil,
  t_new_chunk: [Nx.t()],
  t_new_rk_interpolate: Nx.t() | nil,
  t_old: Nx.t() | nil,
  terminal_event: integration_status(),
  terminal_output: integration_status(),
  timestamp_ms: integer() | nil,
  timestamp_start_ms: integer() | nil,
  x_new: Nx.t() | nil,
  x_new_chunk: [Nx.t()],
  x_new_rk_interpolate: Nx.t() | nil,
  x_old: Nx.t() | nil
}

Functions

@spec abs_rel_norm_opts(Keyword.t()) :: Keyword.t()

Gets the default values used by the absolute-relative norm; e.g., abs_tol, rel_tol, and norm_control

@spec elapsed_time_ms(t()) :: pos_integer()

Returns the total elapsed time for the integration (in milleseconds)

Link to this function

integrate(stepper_fn, interpolate_fn, ode_fn, t_start, t_end, fixed_times, initial_tstep, x0, order, opts \\ [])

View Source
@spec integrate(
  stepper_fn :: Integrator.RungeKutta.stepper_fn_t(),
  interpolate_fn :: Integrator.RungeKutta.interpolate_fn_t(),
  ode_fn :: Integrator.RungeKutta.ode_fn_t(),
  t_start :: Nx.t(),
  t_end :: Nx.t(),
  fixed_times :: [Nx.t()] | nil,
  initial_tstep :: Nx.t(),
  x0 :: Nx.t(),
  order :: integer(),
  opts :: Keyword.t()
) :: t()

Integrates a set of ODEs.

Options

  • :abs_tol (term/0) - The absolute tolerance used when computing the absolute relative norm. Defaults to 1.0e-06 in the Nx type that's been specified.

  • :event_fn - A 2 arity function which determines whether an event has occured. If so, the integration is halted. The default value is nil.

  • :max_number_of_errors (integer/0) - The maximum number of permissible errors before the integration is halted. The default value is 5000.

  • :max_step (term/0) - The default max time step. The default value is determined by the start and end times.

  • :norm_control (boolean/0) - Indicates whether norm control is to be used when computing the absolute relative norm. The default value is true.

  • :output_fn - A 2 arity function which is called at each output point. The default value is nil.

  • :refine - Indicates the number of additional interpolated points. 1 means no interpolation; 2 means one additional interpolated point; etc. :fixed_times means that the output times are fixed. The default value is 4.

  • :rel_tol (term/0) - The relative tolerance used when computing the absolute relative norm. Defaults to 1.0e-03 in the Nx type that's been specified.

  • :speed - :no_delay means to simulate as fast as possible. 1.0 means real time, 2.0 means twice as fast as real time, 0.5 means half as fast as real time, etc. The default value is :no_delay.

  • :store_results? (boolean/0) - Indicates whether or not to store the results of the integration. The default value is true.

Additional Options

Also see the options for the Integrator.NonLinearEqnRoot.find_zero/4 which are passed into integrate/10.

Originally adapted from the Octave integrate_adaptive.m

See Wikipedia

Link to this function

options_schema_adaptive_stepsize_only()

View Source
Link to this function

starting_stepsize(order, ode_fn, t0, x0, abs_tol, rel_tol, opts \\ [])

View Source
@spec starting_stepsize(
  order :: integer(),
  ode_fn :: Integrator.RungeKutta.ode_fn_t(),
  t0 :: Nx.t(),
  x0 :: Nx.t(),
  abs_tol :: Nx.t(),
  rel_tol :: Nx.t(),
  opts :: Keyword.t()
) :: Nx.t()

Computes a good initial timestep for an ODE solver of order order using the algorithm described in the reference below.

The input argument ode_fn, is the function describing the differential equations, t0 is the initial time, and x0 is the initial condition. abs_tol and rel_tol are the absolute and relative tolerance on the ODE integration.

Originally based on the Octave starting_stepsize.m.

Reference:

E. Hairer, S.P. Norsett and G. Wanner, "Solving Ordinary Differential Equations I: Nonstiff Problems", Springer.