gemseo.algos.ode.ode_problem module#

ODE problem.

class ODEProblem(func, initial_state, times, jac_function_wrt_state=None, jac_function_wrt_desvar=None, adjoint_wrt_state=None, adjoint_wrt_desvar=None, solve_at_algorithm_times=False, event_functions=())[source]#

Bases: BaseProblem

First-order Ordinary Differential Equation (ODE).

A first-order ODE is written as

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

where \(f\) is called the right-hand side (RHS) of the ODE and \(s(t)\) is the state vector at time \(t\).

Parameters:
  • func (RHSFuncType | RealArray) -- The RHS function \(f\).

  • initial_state (RealArray) -- The initial state.

  • times (RealArray) -- The time interval of integration and the times of interest where the state must be stored.

  • jac_function_wrt_state (RHSJacType) -- The Jacobian of \(f\) with respect to state. Either a constant matrix or a function to compute it at a given time and state. If None, it will be approximated.

  • jac_function_wrt_desvar (RHSJacType) -- The Jacobian of \(f\) with respect to the design variables. Either a constant matrix or a function to compute it at a given time and state. If None, it will be approximated. Since the design variables are supposed fixed during the integration of the ODE, this Jacobian cannot be checked by the method check_jacobian().

  • adjoint_wrt_state (RHSJacType) -- The adjoint relative to the state when using an adjoint-based ODE solver.

  • adjoint_wrt_desvar (RHSJacType) -- The adjoint relative to the design variables when using an adjoint-based ODE solver.

  • solve_at_algorithm_times (bool) --

    Whether to solve the ODE chosen by the algorithm.

    By default it is set to False.

  • event_functions (Iterable[RHSFuncType]) --

    The event functions, for which the integration stops when they get equal to 0. If empty, the solver will solve the ODE for the entire assigned time interval.

    By default it is set to ().

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, time=None, approximation_mode=ApproximationMode.FINITE_DIFFERENCES, step=1e-06, error_max=1e-08)[source]#

Check if the analytical Jacobian with respect to the state is correct.

Parameters:
  • state (ndarray[Any, dtype[floating[Any]]]) -- The state.

  • time (float | None) -- The time of evaluation of the function. If None, use self.__time_interval.initial.

  • approximation_mode (ApproximationMode) --

    The approximation mode.

    By default it is set to "finite_differences".

  • step (float) --

    The step for the approximation of the gradients.

    By default it is set to 1e-06.

  • error_max (float) --

    The maximum value of the error.

    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.

Return type:

None

update_times(initial_time=None, final_time=None, times=None)[source]#

Update the solution times of the ODE.

Parameters:
  • initial_time (float | None) -- The initial time.

  • final_time (float | None) -- The final time.

  • times (ndarray[Any, dtype[floating[Any]]] | None) -- The vector of time instants (sorted in ascending order).

Raises:

ValueError -- If the initial time is not lower than the final time.

Return type:

None

property evaluation_times: ndarray[Any, dtype[floating[Any]]] | None#

The times of interest where the state is computed.

If None, the ODE is integrated in the interval [0, 1] by default.

event_functions: Iterable[RHSFuncType]#

The event functions, for which the integration stops when they get equal to 0.

initial_state: RealArray#

The state at the initial time.

jac_function_wrt_desvar: RHSFuncType#

The function to compute the Jacobian of \(f\) with respect to the design variables.

jac_function_wrt_state: RHSFuncType#

The function to compute the Jacobian of \(f\) with respect to the state.

result: ODEResult#

The result of the ODE problem.

rhs_function: RHSFuncType#

The RHS function \(f\), function of the time and state.

solve_at_algorithm_times: bool#

Whether to solve the ODE only at the times of interest.

property time_interval: ndarray[Any, dtype[floating[Any]]] | None#

The time interval in which the ODE is solved.

If None, the ODE is integrated in the interval [0, 1] by default.

class TimeInterval(initial, final)[source]#

Bases: NamedTuple

A time interval.

Create new instance of TimeInterval(initial, final)

Parameters:
final: float#

The final time.

initial: float#

The initial time.