Skip to content

Commit

Permalink
reverted
Browse files Browse the repository at this point in the history
  • Loading branch information
EveCharbie committed Nov 5, 2024
1 parent fab9e8d commit 80fc120
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 5 additions & 1 deletion bioptim/dynamics/integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ def __init__(self, ode: dict, ode_opt: dict):
self._n_step = ode_opt["number_of_finite_elements"]
super(RK, self).__init__(ode, ode_opt)

@property
def _integration_time(self):
return self.t_span_sym[1] / self._n_step

@property
def shape_xf(self):
return [self.x_sym.shape[0], 1]
Expand Down Expand Up @@ -309,7 +313,7 @@ def dxdt(
d = numerical_timeseries

for i in range(1, self._n_step + 1):
t = self.t_span_sym[0] + self.h * (i - 1)
t = self.t_span_sym[0] + self._integration_time * (i - 1)
x[:, i] = self.next_x(t, x[:, i - 1], u, p, a, d)
if self.model.nb_quaternions > 0:
x[:, i] = self.model.normalize_state_quaternions(x[:, i])
Expand Down
11 changes: 5 additions & 6 deletions tests/shard6/test_time_dependent_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ def integrate(time_vector, states, controls, dyn_fun, n_shooting=30, n_steps=5):
u_this_time = controls[:, i_shooting]
current_time = dt * i_shooting
for i_step in range(n_steps):
k1 = dyn_fun(current_time, tf, x_this_time, u_this_time)
k2 = dyn_fun(current_time + h / 2, tf, x_this_time + h / 2 * k1, u_this_time)
k3 = dyn_fun(current_time + h / 2, tf, x_this_time + h / 2 * k2, u_this_time)
k4 = dyn_fun(current_time + h, tf, x_this_time + h * k3, u_this_time)
k1 = dyn_fun(current_time, x_this_time, u_this_time)
k2 = dyn_fun(current_time + h / 2, x_this_time + h / 2 * k1, u_this_time)
k3 = dyn_fun(current_time + h / 2, x_this_time + h / 2 * k2, u_this_time)
k4 = dyn_fun(current_time + h, x_this_time + h * k3, u_this_time)
x_this_time += h / 6 * (k1 + 2 * k2 + 2 * k3 + k4)
current_time += h
x_integrated[:, i_shooting + 1] = x_this_time
Expand Down Expand Up @@ -447,13 +447,12 @@ def test_time_dependent_problem(n_phase, integrator, control_type, minimize_time
npt.assert_almost_equal(sol.decision_time()[-1], 1.01985, decimal=5)

time_sym = MX.sym("T", 1, 1)
tf_sym = ocp.nlp[0].tf_mx
states_sym = ocp.nlp[0].states.mx
controls_sym = ocp.nlp[0].controls.mx

dyn_fun = Function(
"dynamics",
[time_sym, tf_sym, states_sym, controls_sym],
[time_sym, states_sym, controls_sym],
[
time_dynamic(
time_sym,
Expand Down

0 comments on commit 80fc120

Please sign in to comment.