1. A method comprising: calculating, using a processor, a first state of a system under a first set of constraints at a first time sample in a simulation of the system; calculating, using a processor, a second state of the system under the first set of constraints at a second time sample in the simulation of the system; detecting, using a processor, an event signaling a change from the first set of constraints to a second set of constraints, the event occurring between the first time sample and the second time sample; and calculating, using a processor, a new state of the system under the second set of constraints at the second time sample, the new state being calculated based at least in part on an energy of error function, the energy of error function being a mathematical composition of: an error function that finds a difference between a third state of the system under the second set of constraints and the second state of the system, and an energy function for the system as dictated by one or more equations that represent one or more dynamics of the system.