Skip to content

Integrator Configuration

Configuration classes and types for controlling integrator behavior.


IntegratorConfig

IntegratorConfig(abs_tol: float = 1e-06, rel_tol: float = 0.001, initial_step: float = None, min_step: float = Ellipsis, max_step: float = Ellipsis, step_safety_factor: float = Ellipsis, min_step_scale_factor: float = Ellipsis, max_step_scale_factor: float = Ellipsis, max_step_attempts: int = 10, fixed_step_size: float = None)

Configuration for numerical integrators.

Controls error tolerances, step size limits, and other integration parameters.

Parameters:

Name Type Description Default
abs_tol float

Absolute error tolerance. Defaults to 1e-6.

1e-06
rel_tol float

Relative error tolerance. Defaults to 1e-3.

0.001
initial_step float

Initial step size. Defaults to None (auto).

None
min_step float

Minimum step size. Defaults to 1e-12.

Ellipsis
max_step float

Maximum step size. Defaults to 900.0.

Ellipsis
step_safety_factor float

Safety factor for step control. Defaults to 0.9.

Ellipsis
min_step_scale_factor float

Minimum step scaling. Defaults to 0.2.

Ellipsis
max_step_scale_factor float

Maximum step scaling. Defaults to 10.0.

Ellipsis
max_step_attempts int

Maximum step attempts. Defaults to 10.

10
fixed_step_size float

Fixed step size for fixed-step integrators. Defaults to None.

None
Example
import brahe as bh

# Create default configuration
config = bh.IntegratorConfig()

# Create fixed-step configuration
config = bh.IntegratorConfig.fixed_step(1.0)

# Create adaptive configuration with custom tolerances
config = bh.IntegratorConfig.adaptive(abs_tol=1e-9, rel_tol=1e-6)

# Customize configuration
config = bh.IntegratorConfig(
    abs_tol=1e-8,
    rel_tol=1e-6,
    max_step=100.0,
    min_step=0.001
)

Initialize instance.

abs_tol property

abs_tol: Any

Get absolute error tolerance.

initial_step property

initial_step: Any

Get initial step size.

max_step property

max_step: Any

Get maximum step size.

max_step_attempts property

max_step_attempts: Any

Get maximum step attempts.

max_step_scale_factor property

max_step_scale_factor: Any

Get maximum step scale factor.

min_step property

min_step: Any

Get minimum step size.

min_step_scale_factor property

min_step_scale_factor: Any

Get minimum step scale factor.

rel_tol property

rel_tol: Any

Get relative error tolerance.

step_safety_factor property

step_safety_factor: Any

Get step safety factor.

adaptive builtin

adaptive(abs_tol: float, rel_tol: float) -> IntegratorConfig

Create a configuration for adaptive-step integration.

Parameters:

Name Type Description Default
abs_tol float

Absolute error tolerance

required
rel_tol float

Relative error tolerance

required

Returns:

Name Type Description
IntegratorConfig IntegratorConfig

Configuration for adaptive-step integration

Example
import brahe as bh
config = bh.IntegratorConfig.adaptive(1e-9, 1e-6)

fixed_step builtin

fixed_step(step_size: float) -> IntegratorConfig

Create a configuration for fixed-step integration.

Parameters:

Name Type Description Default
step_size float

Fixed timestep in seconds

required

Returns:

Name Type Description
IntegratorConfig IntegratorConfig

Configuration for fixed-step integration

Example
import brahe as bh
config = bh.IntegratorConfig.fixed_step(1.0)

AdaptiveStepResult

AdaptiveStepResult()

Result from an adaptive integration step.

Contains the new state, actual timestep used, error estimate, and suggested next step.

Example
import brahe as bh
import numpy as np

def dynamics(t, state):
    return np.array([state[1], -state[0]])

integrator = bh.RKF45Integrator(2, dynamics)
state = np.array([1.0, 0.0])

result = integrator.step(0.0, state, 0.1)
print(f"New state: {result.state}")
print(f"Step used: {result.dt_used}")
print(f"Error: {result.error_estimate}")
print(f"Next step: {result.dt_next}")

Initialize instance.

dt_next property

dt_next: float

Get the suggested next timestep.

Returns:

Name Type Description
float float

Suggested timestep for next iteration

dt_used property

dt_used: float

Get the actual timestep used.

Returns:

Name Type Description
float float

Timestep actually used (may be smaller than requested)

error_estimate property

error_estimate: float

Get the estimated truncation error.

Returns:

Type Description
float

float | None: Estimated local truncation error (None for fixed-step integrators)

state property

state: ndarray

Get the new state vector.

Returns:

Name Type Description
ndarray ndarray

State vector at time t + dt_used

See Also