Skip to content

Add ExpressionBasedPathForce#4035

Merged
nickbianco merged 7 commits intomainfrom
expression_based_path_spring
Mar 19, 2025
Merged

Add ExpressionBasedPathForce#4035
nickbianco merged 7 commits intomainfrom
expression_based_path_spring

Conversation

@nickbianco
Copy link
Member

@nickbianco nickbianco commented Mar 19, 2025

Fixes issue #4034

Brief summary of changes

Adds ExpressionBasedPathForce, which can be used to create non-linear path springs or other path-based force elements dependent on a user-provided expression. Includes some minor drive-by changes to CMake files based on recently removed sandbox files.

Testing I've completed

Added a test to testForces.cpp. I have not tested the updated bindings.

Looking for feedback on...

CHANGELOG.md (choose one)

  • updated.

This change is Reviewable

Copy link
Member

@aymanhab aymanhab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly clarifying questions but otherwise LGTM

Reviewed 8 of 8 files at r1.
Reviewable status: 8 of 9 files reviewed, 4 unresolved discussions (waiting on @carmichaelong)


OpenSim/Simulation/Model/ExpressionBasedPathForce.cpp line 75 at r1 (raw file):

        (SimTK::isNaN(get_resting_length()) || get_resting_length() < 0),
        Exception,
        "Expected the 'resting_length' property to be less than zero, but "

Expected length to be less than zero? typo in the message?


OpenSim/Simulation/Model/ExpressionBasedPathForce.cpp line 124 at r1 (raw file):

    AbstractGeometryPath& path = updPath();
    if (path.getPreScaleLength(s) > 0.0) {

Not sure how this works (how/if PreScale was called). Should we explicitly allow this class to handle prescale/postscale in case we decide to change default behavior?


OpenSim/Simulation/Model/ExpressionBasedPathForce.h line 111 at r1 (raw file):

    ExpressionBasedPathForce(const std::string& name, 
            double restLength, const std::string& expression, bool clampStretch);

These constructors look quite similar, can we combine with a default value for clampStretch?


OpenSim/Simulation/Test/testForces.cpp line 514 at r1 (raw file):

    double ldot = force.getLengtheningSpeed(osim_state);
    double analytical_force = 2.0 / (stretch * stretch) - 
                              3.0 * (stretch - 0.2) * (1 + 0.0123456789 * ldot);

Love this test 👍

Copy link
Member Author

@nickbianco nickbianco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Address all comments and ready for review again.

Reviewable status: 8 of 9 files reviewed, 4 unresolved discussions (waiting on @aymanhab and @carmichaelong)


OpenSim/Simulation/Model/ExpressionBasedPathForce.h line 111 at r1 (raw file):

Previously, aymanhab (Ayman Habib) wrote…

These constructors look quite similar, can we combine with a default value for clampStretch?

I think it's better to separate them like this for use in scripting, or at least I don't think SWIG will create separate constructors if a default argument is used for clampStretch.


OpenSim/Simulation/Model/ExpressionBasedPathForce.cpp line 75 at r1 (raw file):

Previously, aymanhab (Ayman Habib) wrote…

Expected length to be less than zero? typo in the message?

Good catch! Done.


OpenSim/Simulation/Model/ExpressionBasedPathForce.cpp line 124 at r1 (raw file):

Previously, aymanhab (Ayman Habib) wrote…

Not sure how this works (how/if PreScale was called). Should we explicitly allow this class to handle prescale/postscale in case we decide to change default behavior?

This is based on what PathSpring does. It seems like a reasonable modification to make here too. If we do change default behavior, then we'll have to change it in PathSpring too, so it might make sense to keep the behavior of those classes consistent for now.


OpenSim/Simulation/Test/testForces.cpp line 514 at r1 (raw file):

Previously, aymanhab (Ayman Habib) wrote…

Love this test 👍

Done.

@nickbianco nickbianco requested review from aymanhab and removed request for aymanhab and carmichaelong March 19, 2025 19:16
Copy link
Member

@aymanhab aymanhab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for one comment to resolve

Reviewed 1 of 1 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nickbianco)


OpenSim/Simulation/Model/ExpressionBasedPathForce.h line 111 at r1 (raw file):

Previously, nickbianco (Nick Bianco) wrote…

I think it's better to separate them like this for use in scripting, or at least I don't think SWIG will create separate constructors if a default argument is used for clampStretch.

Actually SWIG handles this exactly as expected by creating two functions, so I'd remove the second constructor to eliminate the possibility that they get out of sync.

Copy link
Member Author

@nickbianco nickbianco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for final review.

Reviewable status: 8 of 9 files reviewed, 1 unresolved discussion (waiting on @aymanhab)


OpenSim/Simulation/Model/ExpressionBasedPathForce.h line 111 at r1 (raw file):

Previously, aymanhab (Ayman Habib) wrote…

Actually SWIG handles this exactly as expected by creating two functions, so I'd remove the second constructor to eliminate the possibility that they get out of sync.

Ah, excellent! Done.

Copy link
Member

@aymanhab aymanhab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @nickbianco
:lgtm:

Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @nickbianco)

@nickbianco
Copy link
Member Author

Ubuntu failure is unrelated. Merging.

@nickbianco nickbianco merged commit d3d182a into main Mar 19, 2025
10 of 12 checks passed
@nickbianco nickbianco deleted the expression_based_path_spring branch June 25, 2025 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants