gemseo / algos / ode

Hide inherited members

ode_problem module

Ordinary differential equation problem.

class gemseo.algos.ode.ode_problem.ODEProblem(func, initial_state, initial_time, final_time, jac=None, time_vector=None)[source]

Bases: BaseProblem

First-order ordinary differential equation (ODE).

\[\frac{ds(t)}{dt} = f(t, s(t)).\]

\(f\) is called the right-hand side of the ODE.

Parameters:
  • func (Callable[[NDArray[float], NDArray[float]], NDArray[float]] | NDArray[float]) – The right-hand side of the ODE.

  • initial_state (ArrayLike) – The initial state of the ODE.

  • initial_time (float) – The start of the integration interval.

  • final_time (float) – The end of the integration interval.

  • jac (Callable[[NDArray[float], NDArray[float]], NDArray[float]] | NDArray[float] | None) – The Jacobian of the right-hand side of the ODE.

  • time_vector (NDArray[float] | None) – The time vector for the solution.

check()[source]

Ensure the parameters of the problem are consistent.

Raises:

ValueError – If the state and time shapes are inconsistent.

Return type:

None

check_jacobian(state_vector, approximation_mode=ApproximationMode.FINITE_DIFFERENCES, step=1e-06, error_max=1e-08)[source]

Check if the analytical jacobian is correct.

Compare the value of the analytical jacobian to a finite-element approximation of the jacobian at user-specified points.

Parameters:
  • state_vector (ArrayLike) – The state vector at which the jacobian is checked.

  • approximation_mode (ApproximationMode) –

    The approximation mode.

    By default it is set to “finite_differences”.

  • step (float) –

    The step used to approximate the gradients.

    By default it is set to 1e-06.

  • error_max (float) –

    The error threshold above which the jacobian is deemed to be incorrect.

    By default it is set to 1e-08.

Raises:

ValueError – Either if the approximation method is unknown, if the shapes of the analytical and approximated Jacobian matrices are inconsistent or if the analytical gradients are wrong.

Returns:

Whether the jacobian is correct.

Return type:

None

initial_state: NDArray[float]

The initial conditions \((t_0,s_0)\) of the ODE.

integration_interval: tuple[float, float]

The interval of integration.

jac: Callable[[NDArray[float], NDArray[float]], NDArray[float]]

The Jacobian function of the right-hand side of the ODE.

result: ODEResult

The result of the ODE problem.

rhs_function: Callable[[NDArray[float], NDArray[float]], NDArray[float]]

The right-hand side of the ODE.

property time_vector

The times at which the solution shall be evaluated.

Examples using ODEProblem

Solve an ODE: the Van der Pol problem

Solve an ODE: the Van der Pol problem