Skip to content

Commit

Permalink
refactor : very small but remove if, in forward dynamics to handle an…
Browse files Browse the repository at this point in the history
…d switch between cases.
  • Loading branch information
Ipuch committed Oct 11, 2024
1 parent 38974b5 commit 6209411
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions bioptim/dynamics/dynamics_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,19 +1129,17 @@ def forward_dynamics(
else:
qdot_var_mapping = BiMapping([i for i in range(qdot.shape[0])], [i for i in range(qdot.shape[0])]).to_first

if external_forces is None:
if with_contact:
qddot = nlp.model.constrained_forward_dynamics(q, qdot, tau)
else:
qddot = nlp.model.forward_dynamics(q, qdot, tau)
dynamics_functions = {
(True, True): nlp.model.constrained_forward_dynamics,
(True, False): nlp.model.forward_dynamics,
(False, True): lambda q, qdot, tau: nlp.model.constrained_forward_dynamics(q, qdot, tau, external_forces),
(False, False): lambda q, qdot, tau: nlp.model.forward_dynamics(q, qdot, tau, external_forces),
}

return qdot_var_mapping.map(qddot)
else:
if with_contact:
qddot = nlp.model.constrained_forward_dynamics(q, qdot, tau, external_forces)
else:
qddot = nlp.model.forward_dynamics(q, qdot, tau, external_forces)
return qdot_var_mapping.map(qddot)
dynamics_function = dynamics_functions[(external_forces is None, with_contact)]

qddot = dynamics_function(q, qdot, tau)
return qdot_var_mapping.map(qddot)

@staticmethod
def inverse_dynamics(
Expand Down

0 comments on commit 6209411

Please sign in to comment.