Page 1 of 1

Changing a force parameter during a simulation

Posted: Tue Aug 31, 2021 5:18 pm
by jonperdomo
Hi everyone,

I am looking for a GUI or C++ tool that will enable me to update a force parameter in the middle of a simulation. Specifically, is it possible to run a simulation from 0-1s, then from 1-2s update the rotational stiffness for a Bushing Force object? https://simtk.org/api_docs/opensim/api_ ... Force.html

Thank you!

-Jon

Re: Changing a force parameter during a simulation

Posted: Wed Sep 01, 2021 3:38 am
by tkuchida
If computation time isn't a big issue, you could use the following algorithm:
  1. load model and call initSystem()
  2. run 1-second simulation
  3. edit bushing parameter and call initSystem()
  4. for each state variable, copy value from final time point of first simulation into new state
  5. run 1-second simulation
If computation time is a concern, you should avoid calling initSystem() in the middle---which means that you will need to avoid editing the model. You could try creating two bushings (one with parameter 1 and the other with parameter 2) and using the setAppliesForce() method to turn them on/off (modifying the state rather than the model):
  1. load model and call initSystem()
  2. bushing1.setAppliesForce(state, True)
  3. bushing2.setAppliesForce(state, False)
  4. run 1-second simulation
  5. bushing1.setAppliesForce(state, False)
  6. bushing2.setAppliesForce(state, True)
  7. run 1-second simulation

Re: Changing a force parameter during a simulation

Posted: Wed Sep 01, 2021 3:37 pm
by jonperdomo
Hi Thomas,

The second solution sounds like it will work great, I will try it. Thank you!

-Jon