Skip to content

Commit

Permalink
refactor: to simplify a loop of external force to generalized forces
Browse files Browse the repository at this point in the history
  • Loading branch information
Ipuch committed Nov 30, 2024
1 parent 53f273e commit 56cb7d5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 1 addition & 5 deletions bionc/bionc_numpy/external_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,8 @@ def to_natural_external_forces(self, Q: NaturalCoordinates) -> np.ndarray:

natural_external_forces = np.zeros((12 * Q.nb_qi(), 1))
for segment_index, segment_external_forces in enumerate(self.external_forces):
segment_forces_on_proximal = []
for external_force in segment_external_forces:
segment_forces_on_proximal += [external_force.transport_on_proximal(Q.vector(segment_index))]

segment_natural_external_forces = np.zeros((12, 1))
for external_force in segment_forces_on_proximal:
for external_force in segment_external_forces:
segment_natural_external_forces += external_force.to_generalized_natural_forces(
Q.vector(segment_index)
)[:, np.newaxis]
Expand Down
3 changes: 3 additions & 0 deletions bionc/bionc_numpy/external_force_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ def transport_on_proximal(

return ExternalForceInGlobalOnProximal(external_forces=new_external_forces)

def to_generalized_natural_forces(self, Qi: SegmentNaturalCoordinates):
"""This function returns the external force in the generalized natural forces [12x1] format."""
return self.transport_on_proximal(Qi).to_generalized_natural_forces(Qi)
4 changes: 4 additions & 0 deletions bionc/bionc_numpy/external_force_global_local_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ def transport_on_proximal(
new_external_forces[0:3] += additional_torque

return ExternalForceInGlobalOnProximal(external_forces=new_external_forces)

def to_generalized_natural_forces(self, Qi: SegmentNaturalCoordinates) -> np.ndarray:
"""This function returns the external force in the generalized natural forces [12x1] format."""
return self.transport_on_proximal(Qi).to_generalized_natural_forces(Qi)
4 changes: 4 additions & 0 deletions bionc/bionc_numpy/external_force_in_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ def transport_on_proximal(
new_external_forces[0:3] += additional_torque

return ExternalForceInGlobalOnProximal(external_forces=new_external_forces)

def to_generalized_natural_forces(self, Qi: SegmentNaturalCoordinates) -> np.ndarray:
"""This function returns the external force in the generalized natural forces [12x1] format."""
return self.transport_on_proximal(Qi).to_generalized_natural_forces(Qi)

0 comments on commit 56cb7d5

Please sign in to comment.