opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
783 stars 316 forks source link

Combines computing value and derivative of muscle curves in Millard #3653

Closed pepbos closed 9 months ago

pepbos commented 9 months ago

This PR replaces separate calls to calcValue and calcDerivative on the muscle curves in Millard2012EquilibriumMuscle by calcValueAndDerivative, which is more efficient.

The MuscleLengthInfo::userDefinedLengthExtras and FiberVelocityInfo::userDefinedVelocityExtras buffers are used to store the derivatives of the curves until needed.

Measuring the wallclock time of Rajagopal forward integration, and CMC running-model (using Millard muscles) shows around 10% perf benefit:

main with this PR
CMC-Running Model 25.8 [s] 22.9 [s] (-12.4%)
Rajagopal Forward Integration 6.4 [s] 5.8 [s] ( -9.8% )

Brief summary of changes

There are 4 relevant muscle curves in Millard2012EquilibriumMuscle which are calling calcValue and calcDerivative, which is combined to calcValueAndDerivative by this PR:

Testing I've completed

Unit tests are passing, and Rajagopal forward simulation as well as CMC on running-model gives no change in results.

CHANGELOG.md


This change is Reviewable

pepbos commented 9 months ago

@adamkewley @tkuchida , Thanks for your feedback, sorry for the break in between, please have a look if you agree with the changes :)

Happy new year!