gemseo / algos / ode

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:
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 (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – 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

func: Callable[[ndarray[Any, dtype[float]], ndarray[Any, dtype[float]]], ndarray[Any, dtype[float]]]

The right-hand side of the ODE.

initial_state: ndarray[Any, dtype[float]]

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

integration_interval: tuple[float, float]

The interval of integration.

jac: Callable[[ndarray[Any, dtype[float]], ndarray[Any, dtype[float]]], ndarray[Any, dtype[float]]]

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

result: ODEResult

The result of the ODE problem.

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