Combining Force components

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Robin Compeyron
Posts: 4
Joined: Wed Apr 28, 2021 8:44 am

Combining Force components

Post by Robin Compeyron » Thu Aug 03, 2023 4:15 am

Hi,
[context below]
My question is: How could I program in cpp a custom Force component where the force applied is a weighted sum of for example SmoothSphereHalfSpaceForce and ExternalForces? Do I need to redo the SmoothSphereHalfSpaceForce computation in Opensim, or is there a way to get the value of the computed force from SimTK?
My first guess is to reprogram the smoothForce in the computeForce method, but maybe I can spare that.


Context for those interested:
I wrote a custom program that can get me (reaction) forces from a FEM simulation that is controlled by a movement in Opensim.
I try to simulate the effect of changing shoe/ground condition to a runner/walker.
My aim would be to use the FEM simulation combined with Moco. As creating a new force component that runs a FEM simulation each time Moco wants to know the force is computationally extremely expensive, my idea would be to run an out-of-the-loop simulation where the reaction forces applied on the foot are a sum of something like SimTK::SmoothSphereHalfSpaceForce and ExternalForces that would be exported from the FEM simulation and the proportion of the external forces is slowly increased until they represent 100%.
The scheme could look like that (very wimplified):
1. Moco simulation with 100%*SimTK::SmoothSphereHalfSpaceForce+0%ExternalForces
-> use calculated movement to run an FEM simulation and get updated ExternalForces
2. Moco simulation with 90%*SimTK::SmoothSphereHalfSpaceForce+10%ExternalForces
-> use calculated movement to run an FEM simulation and get updated ExternalForces
...
(N-1). Moco simulation with 10%*SimTK::SmoothSphereHalfSpaceForce+90%ExternalForces
-> use calculated movement to run an FEM simulation and get updated ExternalForces
N. Moco simulation with 0%*SimTK::SmoothSphereHalfSpaceForce+100%ExternalForces

Optional question if you understand what I try to do: do you have maybe other ideas how to couple Moco with a FEM simulation? :-)

Thank you,

Robin

User avatar
Pasha van Bijlert
Posts: 227
Joined: Sun May 10, 2020 3:15 am

Re: Combining Force components

Post by Pasha van Bijlert » Thu Aug 03, 2023 2:50 pm

Hi Robin,

Without commenting on whether this is the best approach to try to combine Moco with FEM simulations (I don't know), I'm wondering why you need a custom force component to achieve what you've described. If what you want is a weighted sum of external (FEM-acquired) forces and regular contact forces computed using SmoothSphereHalfSpaceForce - why not just scale down the external forces and add them to the model as external loads? This will result in a lower contact force from SSHSForce anyway, right, because the external force is now taking some of the load?

Cheers,
Pasha

User avatar
Robin Compeyron
Posts: 4
Joined: Wed Apr 28, 2021 8:44 am

Re: Combining Force components

Post by Robin Compeyron » Fri Aug 04, 2023 9:29 am

Hi Pasha,

I like the way you tackle the problem.

Just to be on the same page: when the external force is taking some of the load, the sshsForce decreases its force by elevating slightly the contact sphere in the halfspace.
In my application rising the "point of contact" means that the FEM external forces will decrease. So by doing what you suggest the Optimization out-of-the-loop should find an optimum where the combination of both external forces and lower SSHSForces produce the necessary amount for the movement. Maybe by playing with the contact parameters I can find a combination where the rest amount of the SSHSForces is small enough to be negligeable in comparison to the externalForces. Thanks for the inspiration, I will try to find out if I can come with good results.

Also to clarify why I would like a combination: I am hoping that with a combination I can get lower height difference at contact which would mean lower force differences in my FEM simulation which would bring stability in the out-of-the-loop optimization. But I am not sure neither if that will work.

Thank you for your answer!

Bests,

Robin

User avatar
Pasha van Bijlert
Posts: 227
Joined: Sun May 10, 2020 3:15 am

Re: Combining Force components

Post by Pasha van Bijlert » Sat Aug 05, 2023 2:35 am

Hi Robin,

Ah yeah I'd overlooked that, you'll get less penetration into the ground which of course will change the overall kinematics, which will throw off the procedure. You could try proportionally decreasing the plane strain modulus of the SSHS force as you increase the weighting of the external force? Would be curious to hear if this works out!

Cheers,
Pasha

User avatar
Robin Compeyron
Posts: 4
Joined: Wed Apr 28, 2021 8:44 am

Re: Combining Force components

Post by Robin Compeyron » Mon Aug 07, 2023 12:06 am

Hi Pasha,
I'll write here if I get good result by doing that. Let's see!
Bests,
Robin

POST REPLY