Page 1 of 1
Removing Forces
Posted: Tue Oct 29, 2019 6:33 pm
by gideonsimpson
I was experimenting with a problem where I let my system run for some amount of time, call
Code: Select all
simulation.system.removeForce(idx)
where idx corresponds to the index of the force I want to remove, and then call
to run for some additional time. I am finding that the system continues to evolve as though the removed force were still present. Is that not what the removeForce method does? Or must something else be done?
Re: Removing Forces
Posted: Tue Oct 29, 2019 8:50 pm
by peastman
When you create a Context, it copies out all the information about the System. From that point on, any changes to the System have no effect on the existing Context.
You can force it to pick up the changes by calling reinitialize() on the Context. That throws out all existing information and rebuilds its data structures from scratch, which means state information (positions, velocities, etc.) is lost. If you specify preserveState=True, it will try to preserve the state information by first creating a checkpoint, then trying to reload the checkpoint after the context is reinitialized. That will work as long as nothing has changed that alters the content of checkpoints. For removing a Force, that basically means the Force can't have defined any global parameters, since those get stored in checkpoints. Otherwise, you'll have to manually restore all relevant state information after reinitializing the context.
Re: Removing Forces
Posted: Wed Oct 30, 2019 4:01 am
by gideonsimpson
I'll give that a shot. Two follow up questions. Is this the intended use of removeForce? Is there a simpler/better way to accomplish what I'm trying to do?
Re: Removing Forces
Posted: Wed Oct 30, 2019 8:36 am
by peastman
I'm not sure exactly what you're trying to do, so I don't know if there's a better way. But that sounds like one reasonable way of doing it.
Re: Removing Forces
Posted: Wed Oct 30, 2019 11:31 am
by gideonsimpson
What I'm trying to do is to simulate a system where I turn certain forces on/off at specific times.