ode_problem module¶
Ordinary differential equation problem.
- class gemseo.algos.ode.ode_problem.ODEProblem(func, initial_state, initial_time, final_time, jac=None, jac_desvar=None, adjoint_wrt_state=None, adjoint_wrt_desvar=None, time_vector=None)[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 (Callable[[float, NumberArray], NumberArray]) – The RHS function \(f\). It will be called as func(time, state) as necessary.
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[[float, NumberArray], NumberArray] | NumberArray | None) – The function to compute the Jacobian of \(f\). If
Callable
, the Jacobian is assumed to be dependent on time and state. It will be called asjac(time, state)
as necessary. IfNumberArray
, the Jacobian is assumed to be constant. IfNone
, the Jacobian will be approximated by finite differences.jac_desvar (Callable[[float, NumberArray], NumberArray] | None) – The function to compute the Jacobian of \(f\) relative to the design variables. If
None
, use a solver that doesn’t require the adjoint.adjoint_wrt_state (NumberArray | None) – The adjoint relative to the state. If
None
, use a solver that doesn’t require the adjoint.adjoint_wrt_desvar (NumberArray | None) – The adjoint relative to the design variables. If
None
, use a solver that doesn’t require the adjoint.time_vector (NumberArray | None) – The time vector for the solution. If
None
, the solver will select times for which the computed solution is stored.
- 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 Jacobian function is correct.
At a given state, compare the value of the Jacobian computed by the function provided by ther user to an approximated value computed by finite-differences for example.
- Parameters:
state_vector (ArrayLike) – The state 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 – When the Jacobian function is wrong.
- Return type:
None
- adjoint_wrt_desvar: NumberArray
The adjoint of the problem relative to the design variables.
- adjoint_wrt_state: NumberArray
The adjoint of the problem relative to the state.
- initial_state: NumberArray
The initial conditions \((t_0,s_0)\) of the ODE.
- jac: Callable[[float, NumberArray], NumberArray] | NumberArray | None
The function to compute the Jacobian of \(f\).
If
Callable
, the Jacobian is assumed to be dependent on time and state. It will be called asjac(time, state)
as necessary. IfNumberArray
, the Jacobian is assumed to be constant. IfNone
, the Jacobian will be approximated by finite differences.
- jac_desvar: Callable[[float, NumberArray], NumberArray]
The function to compute the Jacobian of \(f\) relative to the design variables.
- result: ODEResult
The result of the ODE problem.
- rhs_function: Callable[[float, NumberArray], NumberArray]
The function \(f\).
- property time_vector
The times at which the solution shall be evaluated.
Examples using ODEProblem¶
Solve an ODE: the Van der Pol problem