Simbody is useful for internal coordinate and coarse grained molecule modeling, large scale mechanical models like skeletons, and anything else that can be modeled as bodies interconnected by joints, acted upon by forces, and restricted by constraints.
-
Tom Lintern
- Posts: 61
- Joined: Mon Dec 13, 2010 5:43 pm
Post
by Tom Lintern » Tue Mar 12, 2013 2:15 pm
Hi,
I just have a question regarding investigating whether my simulations have converged or not within the opensim API. My simulation results are doing a few strange things and just wanted to check my integrator tolerances and how the integrator is terminating. I am wondering how I can return the termination reason? Currently I am trying to return the termination reason after the opensim manager performs the integration but I always get "InvalidTerminationReason", even at very high integrator accuracies. My code segment is below and I would really appreciate any thoughts.
Cheers
Tom
Code: Select all
// Create the integrator for the simulation.
SimTK::RungeKuttaMersonIntegrator integrator(osimModel.getMultibodySystem());
integrator.setAccuracy(0.00001);
// Create the manager
Manager manager(osimModel, integrator);
// Integrate from initial time to final time
manager.setInitialTime(parameters[9]);
manager.setFinalTime(parameters[10]);
std::cout<<"\n\nIntegrating from "<<parameters[9]<<" to "<<parameters[10]<<std::endl;
clock_t t1,t2;
t1 = clock();
manager.integrate(s);
SimTK::Integrator::TerminationReason termReason;
termReason = integrator.getTerminationReason();
SimTK::String termReasonString = integrator.getTerminationReasonString(termReason);
cout<<"\n\nIntegrator termination reason: "<<termReasonString;
-
Michael Sherman
- Posts: 806
- Joined: Fri Apr 01, 2005 6:05 pm
Post
by Michael Sherman » Tue Mar 12, 2013 4:40 pm
Hi, Tom.
I took a look at the OpenSim Manager code and it does not use the SimTK::Integrator's termination handling. It just runs the simulation up until the final time but doesn't tell the integrator that that is the end. So the integrator doesn't know it has terminated. You can check this by telling the integrator yourself, e.g. integ.setFinalTime(1), in which case it should terminate at 1 second with a "ReachedFinalTime" termination reason.
To do what you want you would need to ask the Manager for its termination reason; I don't think it has such a status though. That said, it isn't clear to me what information you are trying to get. The integrator termination reason only reports the results of fairly well-behaved terminations, such as hitting the final time or an event handler requesting termination. It is not an error return; most errors throw exceptions.
Regards,
Sherm
-
Tom Lintern
- Posts: 61
- Joined: Mon Dec 13, 2010 5:43 pm
Post
by Tom Lintern » Sun Mar 17, 2013 1:17 pm
Hi Sherm,
Thanks for the reply. I am just trying to get a feel as to whether the integrator had converged to a solution and if I could get any info out of the termination reporter but it seems the integrator was running to completion.
I do have one question that I have come across since... Do you know what some common reasons why the following error would be returned and what measures I could take to help? I am running the forward simulation in an objective function and the integrator successfully terminates many many times until sometimes it fails. The exception I get is shown below.
Code: Select all
OptimizationExample.cpp Caught exception :
SimTK Exception thrown at Differentiator.cpp:350:
A user function threw an exception when invoked by Differentiator. The exception message was: SimTK Exception thrown at AbstractIntegratorRep.cpp:407:
Integrator step failed at time 13.6459213651765 apparently because:
SimTK Exception thrown at AbstractIntegratorRep.cpp:519:
Error detected by Simbody method AbstractIntegrator::takeOneStep(): Unable to advance time past 13.6459.
(Required condition 't1 > t0' was not met.)
Any help or tips would be great.
Cheers
Tom
-
Michael Sherman
- Posts: 806
- Joined: Fri Apr 01, 2005 6:05 pm
Post
by Michael Sherman » Sun Mar 17, 2013 3:14 pm
Hi, Tom. Sorry that message is so obscure! In general it means that the integrator failed to take a step, so reduced the step size to try a smaller step, and then continued to fail no matter how small a step it attempted until the step size got down to zero.
Some random thoughts:
The most common cause of this problem is inability to satisfy some constraint to the required constraint tolerance. This might be due to constraints reaching an incompatible configuration, for example a prescribed motion that would require breaking a joint.
A second possibility is the presence of a NaN or Infinity in the system derivatives. (In Debug mode you'll get an error message about that, but not in Release because it is expensive to check.) This might be due to a divide by zero, for example.
I notice that the failure you reported is being invoked from the Differentiator, meaning during calculation of the gradient for the optimizer. The Differentiator perturbs the optimization variables but unfortunately does not obey the limits on those variables so might perturb one slightly beyond its limit. You might want to check if something like that could be causing the integration failure.
Otherwise I would suggest that you try to find the exact values of the variables at which the failed forward dynamics occurred, and then try to run that simulation alone, without being inside the optimization loop. Then you could look at it and see what is happening at the point it fails.
Regards,
Sherm